🔐 How to Set Up an SSH Key to Connect to GitHub
February 9, 2026
Using SSH keys allows you to securely connect to GitHub without entering your username and password every time you interact with a repository.
✅ Prerequisites
- Git installed
- A GitHub account
- Terminal access
- macOS / Linux: Terminal
- Windows: Git Bash
Check Git installation:
git --version
1️⃣ Check for Existing SSH Keys
Before creating a new key, check if one already exists:
ls -al ~/.ssh
If you see files like id_ed25519 and id_ed25519.pub (or id_rsa and id_rsa.pub), you already have an SSH key.
2️⃣ Generate a New SSH Key
Generate a new SSH key using the recommended ed25519 algorithm:
ssh-keygen -t ed25519 -C "dbt19@example.com"
If ed25519 is not supported, use RSA instead:
ssh-keygen -t rsa -b 4096 -C "dbt19@example.com"
When prompted:
- Press Enter to accept the default file location
- Optionally enter a passphrase for added security
3️⃣ Start the SSH Agent and Add the Key
Start the SSH agent:
eval "$(ssh-agent -s)"
Add your SSH private key:
ssh-add ~/.ssh/id_ed25519
(Use id_rsa if you generated an RSA key.)
4️⃣ Add the SSH Key to GitHub
Copy the public key
cat ~/.ssh/id_ed25519.pub
Copy the entire output.
Add the key to GitHub
- Go to GitHub → Settings
- Select SSH and GPG keys
- Click New SSH key
- Paste your public key
- Give it a recognizable title (e.g. Dbt19's Laptop)
- Click Add SSH key
5️⃣ Test the SSH Connection
Test your connection to GitHub:
ssh -T git@github.com
If successful, you will see:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
6️⃣ Use SSH with GitHub Repositories
Make sure your repository remote URL uses SSH, not HTTPS.
Example SSH URL:
git@github.com:username/repository-name.git
Clone a repository using SSH:
git clone git@github.com:username/repository-name.git
🛠 Troubleshooting
Permission denied (publickey)?
- Ensure your SSH key is added to GitHub
- Make sure the SSH agent is running
- Verify the repository URL uses SSH
Check which key is being used:
ssh -vT git@github.com
📚 Useful Commands
ssh-add -l # List SSH keys added to the agent
ssh-add -D # Remove all keys from the agent
✅ Done
Your SSH key is now set up and connected to GitHub 🎉