If you're contributing to open source or working with GitHub regularly, you've probably encountered this:
Username for 'https://github.com':
Password for 'https://github.com':
Or worse, GitHub rejects your password because password authentication is no longer supported.
The solution? SSH authentication.
Once configured, you can push, pull, and clone repositories without entering your credentials every time.
In this guide, I'll show you how to configure SSH for Git on Linux or WSL.
Why use SSH?
Instead of authenticating with your username and Personal Access Token (PAT) for every repository, SSH uses a pair of cryptographic keys:
- Private Key → Stays on your computer.
- Public Key → Added to your GitHub account.
When GitHub sees your private key, it verifies your identity automatically.
No passwords.
No tokens.
Just Git.
Prerequisites
- Linux (Ubuntu, Debian, Fedora, etc.) or WSL2
- Git installed
- A GitHub account
Step 1 - Verify SSH is installed
Open your terminal and run:
ssh -V
Example output:
OpenSSH_9.6p1 Ubuntu-3ubuntu13.12, OpenSSL 3.0.13
If you see a version number, you're good to go.
Step 2 - Generate a new SSH key
GitHub recommends using the modern Ed25519 algorithm.
Run:
ssh-keygen -t ed25519 -C "your-email@example.com"
Replace the email with the one associated with your GitHub account.
Example:
ssh-keygen -t ed25519 -C "ayush@example.com"
You'll be asked:
Enter file in which to save the key
Simply press Enter to accept the default location:
~/.ssh/id_ed25519
Step 3 - Choose a passphrase
Next you'll see:
Enter passphrase (empty for no passphrase):
You have two options:
Option 1 (Recommended for personal machines)
Press Enter twice.
This creates the key without a passphrase, making Git authentication seamless.
Option 2 (Recommended for shared or highly secure machines)
Enter a strong passphrase.
This adds an extra layer of security but requires unlocking the key before use.
Step 4 - Start the SSH agent
Run:
eval "$(ssh-agent -s)"
Example output:
Agent pid 12345
The SSH agent securely manages your private keys.
Step 5 - Add your private key
Run:
ssh-add ~/.ssh/id_ed25519
Expected output:
Identity added: /home/user/.ssh/id_ed25519
Step 6 - Copy your public key
Display the public key:
cat ~/.ssh/id_ed25519.pub
You'll see something similar to:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI........ your-email@example.com
Copy the entire line.
Step 7 - Add the key to GitHub
Navigate to:
-> GitHub → Settings → SSH and GPG keys → New SSH key
Give it a meaningful title, for example:
-> Ubuntu WSL - Work Laptop
Paste the copied public key into the Key field.
Click Add SSH key.
Done!
Step 8 - Test the connection
Run:
ssh -T git@github.com
The first time you'll be asked:
The authenticity of host 'github.com' can't be established.
Are you sure you want to continue connecting (yes/no)?
Type:
yes
If everything is configured correctly, you'll see:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
Congratulations! SSH is now configured successfully.
Step 9 - Update existing repositories
If your repositories currently use HTTPS:
https://github.com/username/project.git
Switch them to SSH:
git remote set-url origin git@github.com:username/project.git
Verify:
git remote -v
Expected:
origin git@github.com:username/project.git (fetch)
origin git@github.com:username/project.git (push)
Verify your Git identity
You can also verify your Git configuration:
git config --global --list
Or check specific values:
git config --global user.name
git config --global user.email
If needed, configure them:
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Troubleshooting
Permission denied (publickey)
Ensure your key is loaded:
ssh-add ~/.ssh/id_ed25519
~/.ssh doesn't exist
Generate a new SSH key using the steps above.
The directory will be created automatically.
Git still asks for a username/password
Your repository is likely still using HTTPS.
Check:
git remote -v
If it shows:
https://github.com/...
Switch it to SSH:
git remote set-url origin git@github.com:username/repository.git
Final Thoughts
Setting up SSH takes less than 10 minutes, but it saves countless authentication prompts throughout your development journey.
If you're contributing to open source, working across multiple repositories, or simply want a smoother Git workflow, SSH is well worth the one-time setup.
Happy coding!
Drop a ❤️ if you find it helpful.
Top comments (0)