Skip to content

jaeef/ssh-setup-github-windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

πŸ” How to Set Up SSH for GitHub on Windows

A beginner-friendly, step-by-step guide to authenticating with GitHub using SSH keys β€” no passwords needed after setup.


πŸ“‹ Table of Contents

  1. What is SSH and Why Use It?
  2. Prerequisites
  3. Step 1 β€” Generate Your SSH Key
  4. Step 2 β€” Start the SSH Agent
  5. Step 3 β€” Add Your SSH Key to the Agent
  6. Step 4 β€” Add the Public Key to GitHub
  7. Step 5 β€” Test Your Connection
  8. Step 6 β€” Clone a Repository Using SSH
  9. Troubleshooting
  10. Quick Reference β€” All Commands

What is SSH and Why Use It?

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

Prerequisites

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.


Step 1: Generate Your SSH Key

  1. Open Git Bash (search for it in the Start menu).

  2. 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 the ed25519 algorithm, which is modern, fast, and highly secure.

  1. 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
  1. 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.

  1. 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.


Step 2: Start the SSH Agent

The SSH Agent is a background service that manages your keys so you don't have to re-enter them.

  1. Open Windows PowerShell as Administrator:

    • Press the Windows key, type PowerShell
    • Right-click it β†’ select "Run as Administrator"
  2. 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. βœ…


Step 3: Add Your SSH Key to the Agent

Still in PowerShell (Admin), run:

ssh-add C:/Users/YOU/.ssh/id_ed25519

⚠️ Replace YOU with your actual Windows username.
Example: ssh-add C:/Users/JohnDoe/.ssh/id_ed25519

You can confirm your username by running:

echo $env:USERNAME

If 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.


Step 4: Add the Public Key to GitHub

Now you need to give GitHub your public key so it can recognize you.

4a. Copy your public key

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.com

Copy the entire line β€” don't miss anything.

4b. Add the key to GitHub

  1. Go to github.com and log in.
  2. Click your profile picture (top right) β†’ Settings.
  3. In the left sidebar, click SSH and GPG keys.
  4. Click the green "New SSH key" button.
  5. 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 .pub file
  6. Click "Add SSH key" and confirm with your GitHub password if prompted.

βœ… Your SSH key is now registered with GitHub!


Step 5: Test Your Connection

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.com

You 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 the known_hosts file, you'll need to run ssh -T git@github.com again to regenerate it.


Step 6: Clone a Repository Using SSH

Now you can clone any GitHub repo using SSH instead of HTTPS.

  1. Go to any repository on GitHub.
  2. Click the green "Code" button.
  3. Select the "SSH" tab.
  4. Copy the URL β€” it looks like:
git@github.com:username/repository-name.git
  1. In Git Bash (or any terminal), run:
git clone git@github.com:username/repository-name.git

No password. No prompts. It just works. βœ…


Troubleshooting

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

Quick Reference: All Commands

# ── 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

πŸ“š Further Reading


Made for Windows users who are new to SSH. If this helped you, consider starring ⭐ this repo!

About

A beginner-friendly guide to setting up SSH for GitHub on Windows

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors