A beginner-friendly, step-by-step guide to authenticating with GitHub using SSH keys β no passwords needed after setup.
- What is SSH and Why Use It?
- Prerequisites
- Step 1 β Generate Your SSH Key
- Step 2 β Start the SSH Agent
- Step 3 β Add Your SSH Key to the Agent
- Step 4 β Add the Public Key to GitHub
- Step 5 β Test Your Connection
- Step 6 β Clone a Repository Using SSH
- Troubleshooting
- Quick Reference β All Commands
SSH (Secure Shell) is a protocol that lets you securely connect to remote servers β including GitHub β without typing your username and password every time.
Instead of a password, SSH uses a key pair:
- π Private key β stays on your computer, never shared.
- π Public key β uploaded to GitHub. It's safe to share.
When you connect, GitHub checks if your private key matches the public key on file. If they match, you're authenticated instantly.
Benefits over HTTPS:
- No password prompts when pushing/pulling
- More secure than password-based login
- Works seamlessly with tools like Git Bash, GitHub Desktop, and Sourcetree
Before you begin, make sure you have:
- β A GitHub account
- β Git Bash installed β Download here
- β Windows PowerShell (built into Windows β no download needed)
π‘ What is Git Bash?
Git Bash is a terminal for Windows that lets you run Unix-style commands including Git and SSH tools. Install it with default settings.
-
Open Git Bash (search for it in the Start menu).
-
Run the following command, replacing the email with the one linked to your GitHub account (put email inside the "mail" ):
ssh-keygen -t ed25519 -C "your_email@example.com"π What does this do?
This generates a new SSH key pair using theed25519algorithm, which is modern, fast, and highly secure.
- You'll be prompted:
Enter file in which to save the key (/c/Users/YOU/.ssh/id_ed25519):
Press Enter to accept the default location. Git Bash will create the key at:
C:\Users\YOUR_USERNAME\.ssh\id_ed25519
- Next, you'll be asked for a passphrase:
Enter passphrase (empty for no passphrase):
- You can add a passphrase for extra security.
- You can press Enter to skip it (no passphrase).
β οΈ Note: Some tools like the Unity Package Manager may have issues with SSH passphrases. If you're unsure, press Enter to skip.
- Git Bash will confirm your key was created and show output like:
Your identification has been saved in /c/Users/YOU/.ssh/id_ed25519
Your public key has been saved in /c/Users/YOU/.ssh/id_ed25519.pub
π Keep Git Bash open β you'll need the file path shown here in the next step.
The SSH Agent is a background service that manages your keys so you don't have to re-enter them.
-
Open Windows PowerShell as Administrator:
- Press the Windows key, type
PowerShell - Right-click it β select "Run as Administrator"
- Press the Windows key, type
-
Run these two commands (you can paste both at once):
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agentπ What does this do?
The first command sets the SSH Agent service to start manually. The second command starts it right now.
If no error appears, the agent is running. β
Still in PowerShell (Admin), run:
ssh-add C:/Users/YOU/.ssh/id_ed25519
β οΈ ReplaceYOUwith your actual Windows username.
Example:ssh-add C:/Users/JohnDoe/.ssh/id_ed25519
You can confirm your username by running:
echo $env:USERNAMEIf successful, you'll see:
Identity added: C:/Users/YOU/.ssh/id_ed25519 (your_email@example.com)
π Keep PowerShell open β you'll need it again in Step 5.
Now you need to give GitHub your public key so it can recognize you.
Navigate to this folder in File Explorer:
C:\Users\YOUR_USERNAME\.ssh\
Open the file named id_ed25519.pub with Notepad (right-click β Open with β Notepad).
Select everything (Ctrl + A) and copy it (Ctrl + C).
π The file contents look like this:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... your_email@example.comCopy the entire line β don't miss anything.
- Go to github.com and log in.
- Click your profile picture (top right) β Settings.
- In the left sidebar, click SSH and GPG keys.
- Click the green "New SSH key" button.
- Fill in the form:
- Title: Give it a recognizable name (e.g.,
Windows Laptop,My PC) - Key type: Leave it as
Authentication Key - Key: Paste everything you copied from the
.pubfile
- Title: Give it a recognizable name (e.g.,
- Click "Add SSH key" and confirm with your GitHub password if prompted.
β Your SSH key is now registered with GitHub!
Go back to PowerShell (or reopen it as Admin and re-run the two commands from Step 2 if you closed it).
Run:
ssh -T git@github.comYou may see this message on first connection:
The authenticity of host 'github.com (IP)' can't be established.
Are you sure you want to continue connecting (yes/no)?
Type yes and press Enter. This creates a known_hosts file that remembers GitHub's identity.
If everything is set up correctly, you'll see:
Hi YOUR_USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
π You're in! SSH is fully configured.
β οΈ If you ever delete theknown_hostsfile, you'll need to runssh -T git@github.comagain to regenerate it.
Now you can clone any GitHub repo using SSH instead of HTTPS.
- Go to any repository on GitHub.
- Click the green "Code" button.
- Select the "SSH" tab.
- Copy the URL β it looks like:
git@github.com:username/repository-name.git
- In Git Bash (or any terminal), run:
git clone git@github.com:username/repository-name.gitNo password. No prompts. It just works. β
| Problem | Likely Cause | Fix |
|---|---|---|
ssh-add says "Could not open connection to your authentication agent" |
SSH Agent not running | Re-run the two commands in Step 2 |
Permission denied (publickey) from GitHub |
Key not added to GitHub or agent | Redo Steps 3 and 4 |
Warning: Permanently added 'github.com' |
First-time connection | Normal β type yes to continue |
ssh -T works but pushing fails |
Remote URL uses HTTPS, not SSH | Change remote: git remote set-url origin git@github.com:user/repo.git |
| Passphrase asked every time | Agent not caching the key | Make sure the SSH Agent is running and you ran ssh-add |
# ββ Git Bash ββββββββββββββββββββββββββββββββββββββββββββββ
# Generate SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
# ββ PowerShell (Run as Administrator) ββββββββββββββββββββ
# Start SSH Agent
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
# Add SSH key to agent (replace YOU with your Windows username)
ssh-add C:/Users/YOU/.ssh/id_ed25519
# Test connection to GitHub
ssh -T git@github.com- Official GitHub SSH Documentation
- Download Git Bash
- Generating a new SSH key and adding it to the ssh-agent
Made for Windows users who are new to SSH. If this helped you, consider starring β this repo!