This guide walks you through setting up SSH-based authentication for GitHub, enabling secure, passwordless Git operations from your local machine.
- No need to enter username/password every time
- Stronger security with public/private key cryptography
- Recommended by GitHub for daily development
An SSH key pair consists of two files:
- Private key: Stored securely on your machine (
~/.ssh/id_ed25519).
👉 Never share this file. - Public key: Can be safely shared (
~/.ssh/id_ed25519.pub).
👉 This is what you upload to GitHub.
These keys work together to prove your identity without needing to send passwords.
ssh-keygen -t ed25519 -C "your_email@example.com"| Option | Description |
|---|---|
-t ed25519 |
Tells SSH to use the Ed25519 algorithm (fast + secure) |
-C "your_email" |
A label to help identify your key (e.g., your GitHub email) |
Enter file in which to save the key (/home/youruser/.ssh/id_ed25519):
Just press Enter to save it to the default location.
Enter passphrase (empty for no passphrase):
Optional, but recommended. Adds extra protection to your key.You’ll only need to enter this once per session (if usingssh-agent).
If successful, you’ll have:
~/.ssh/id_ed25519 # Your private key (KEEP THIS SAFE)
~/.ssh/id_ed25519.pub # Your public key (Upload this to GitHub)
Now you're ready to add the public key to your GitHub account.
If you set a passphrase for your SSH key, you can add it to the SSH agent to avoid typing the passphrase every time.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519💡 Tip: Use ssh-add -l to verify the key is added.
Copy your public key:
cat ~/.ssh/id_ed25519.pubGo to GitHub → Settings → SSH and GPG keys → New SSH key
Paste the key, name it (e.g. "My Laptop"), and save.
When cloning a repo, use the SSH URL:
git clone git@github.com:yourusername/yourrepo.gitOr, change an existing repo's remote:
git remote set-url origin git@github.com:yourusername/yourrepo.gitssh -T git@github.comExpected output:
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
To manage multiple GitHub accounts or custom keys, create ~/.ssh/config:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519