SSH Keypair Setup for GitHub on Mac
Open Terminal
What is Terminal? A text-based application that allows you to run commands on your Mac using the command line.
How to open Terminal:
- Press
Cmd + Space
to open Spotlight - Type "Terminal" and press Enter
- Alternative: Go to Applications → Utilities → Terminal
1. Generate SSH Key
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
When prompted:
- Press Enter for default location (
~/.ssh/id_rsa
) - Enter passphrase (recommended for security)
2. Add Key to SSH Agent
Start ssh-agent:
eval "$(ssh-agent -s)"
Add key to agent:
ssh-add ~/.ssh/id_rsa
3. Copy Public Key
pbcopy < ~/.ssh/id_rsa.pub
Alternative method:
cat ~/.ssh/id_rsa.pub
Then manually copy the output.
4. Add Key to GitHub
- Go to GitHub.com → Settings → SSH and GPG keys
- Click New SSH key
- Add descriptive title (e.g., "MacBook Pro 2024")
- Paste key into "Key" field
- Click Add SSH key
Direct link: https://github.com/settings/ssh/new
5. Test Connection
ssh -T git@github.com
Expected response:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Configure Git (if needed)
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Clone Repository Example
git clone git@github.com:username/repository.git
Troubleshooting
Permission denied error:
ssh -vT git@github.com
Check if key is loaded:
ssh-add -l
Re-add key if missing:
ssh-add ~/.ssh/id_rsa