This guide explains how to generate and add SSH keys for GitHub authentication.
Run:
ls -l ~/.ssh/id_ed25519.pub
- If the file exists, skip to Step 3.
- If not found, move to Step 2.
Run:
ssh-keygen -t ed25519 -C "your_email@example.com"
- When prompted for a location, press ENTER to accept the default.
- When asked for a passphrase, press ENTER (or set a passphrase for security).
Start the SSH agent:
eval "$(ssh-agent -s)"
Add your key:
ssh-add ~/.ssh/id_ed25519
Verify the key is added:
ssh-add -l
Show the key:
cat ~/.ssh/id_ed25519.pub
Copy the output (starting with ssh-ed25519
).
- Go to GitHub → Settings → SSH and GPG Keys:
https://github.com/settings/keys - Click "New SSH Key".
- Set a Title (e.g., "My Linux Machine").
- Paste the copied SSH key.
- Click "Add SSH Key".
Run:
ssh -T git@github.com
If successful, you should see:
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
Check your GitHub remote URL:
git remote -v
If it uses HTTPS (https://github.com/...
), change it to SSH:
git remote set-url origin git@github.com:yourusername/repository.git
Now, you can push and pull using SSH:
git push origin main
git pull origin main