Quick Start: SSH for GitHub in 5 Minutes
What is SSH in Simple Terms?
Think of SSH keys like a secure key and lock system for your computer to talk to GitHub:
- Private Key = Your actual house key (keep it secret!)
- Public Key = A copy of your lock that you give to GitHub
- When you connect, GitHub tests your key in their lock - if it fits, you’re in!
Step-by-Step Setup (5 minutes)
1. Create Your SSH Key
ssh-keygen -t ed25519 -C "your_email@example.com"
# Press Enter 3 times (uses default locations, no password)
# Creates two files: id_ed25519 (private) and id_ed25519.pub (public)
2. Add Key to SSH Agent
# Start the SSH agent
eval "$(ssh-agent -s)"
# Add your private key
ssh-add ~/.ssh/id_ed25519
3. Add Public Key to GitHub
# Copy your public key to clipboard
cat ~/.ssh/id_ed25519.pub | pbcopy # macOS
# OR
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard # Linux
Then:
- Go to GitHub.com → Settings → SSH and GPG keys
- Click “New SSH key”
- Paste your key and save
4. Test Your Connection
ssh -T git@github.com
# You should see: Hi username! You've successfully authenticated...
🎉 Congratulations! You’re now using SSH with GitHub!
Intermediate Guide: Understanding & Troubleshooting
How SSH Actually Works
The Handshake Process:
- Client says “Hello” → Your computer contacts GitHub
- Server identification → GitHub proves it’s really GitHub
- Key exchange → Both sides agree on a secret code
- Authentication → Your private key proves who you are
- Secure channel → All communication is now encrypted
File Structure
~/.ssh/
├── id_ed25519 # PRIVATE KEY (never share!)
├── id_ed25519.pub # PUBLIC KEY (share with GitHub)
├── known_hosts # Trusted servers list
└── config # Custom settings (optional)
Common Issues & Solutions
“Permission denied (publickey)”
# 1. Check if key is loaded
ssh-add -l
# 2. If no keys listed, add them
ssh-add ~/.ssh/id_ed25519
# 3. Verify GitHub has your PUBLIC key
cat ~/.ssh/id_ed25519.pub
# Should start with "ssh-ed25519" and end with your email
Multiple GitHub Accounts
Create ~/.ssh/config:
# Personal account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
Use with custom URLs:
git clone git@github-personal:username/repo.git
Best Practices
- Use Ed25519 keys (more secure than RSA)
- Add a passphrase for extra security
- Use SSH agent so you don’t type passphrase every time
- Regularly review your GitHub SSH keys