Skip to content

Generating and Using SSH Keys with GitHub on Windows

This guide will walk you through creating a secure SSH key pair, adding it to the SSH agent, and connecting it to your GitHub account using Windows (PowerShell or Git Bash). SSH keys provide a secure way to authenticate with GitHub and avoid entering your password for every git operation.

SSH keys are a way to authenticate securely to GitHub without using a password. This guide covers the process for Windows users using PowerShell or Git Bash.


Step 1: Check for Existing SSH Keys

Open PowerShell or Git Bash and list existing keys:

ls ~/.ssh/

Typical SSH key files have names like id_rsa, id_ed25519, or custom names.

  • If you see files ending with .pub (such as id_ed25519.pub), you already have public keys.
  • If you see private keys (without .pub), you can use them or generate a new one.
  • If there are no files, proceed to generate a new key.

Step 2: Generate a New SSH Key Pair

In your terminal, run:

ssh-keygen -t ed25519 -C "your_email@example.com"
  • Replace "your_email@example.com" with your actual email address.
  • Ed25519 is recommended for security and performance.

When prompted:

  1. Enter file in which to save the key
  2. Press Enter to accept the default (~/.ssh/id_ed25519)
  3. Or type a custom name (e.g., ~/.ssh/github_ed25519) if you want to keep keys organized per service.

  4. Enter passphrase (optional)

  5. For extra security, enter a strong passphrase.
  6. Or, press Enter to leave blank (not recommended for critical use).

Sample output:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/YourUser/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/YourUser/.ssh/id_ed25519
Your public key has been saved in /c/Users/YourUser/.ssh/id_ed25519.pub

Step 3: Add Your SSH Key to the ssh-agent

PowerShell

Start the SSH agent:

Start-Service ssh-agent

Enable automatic start (optional):

Get-Service ssh-agent | Set-Service -StartupType Automatic

Add your SSH key (replace with your actual filename if you used a custom name):

ssh-add ~/.ssh/id_ed25519

Git Bash

Start the agent and add your key:

eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519

Step 4: Add Your SSH Key to GitHub

  1. Copy the public key to your clipboard
    (Use the correct file name: if custom, change accordingly)

PowerShell:

Get-Content ~/.ssh/id_ed25519.pub | clip
Git Bash:
cat ~/.ssh/id_ed25519.pub | clip

  1. Add the key to GitHub:
  2. Go to GitHub.com
  3. Click your profile photo (top right) → Settings
  4. In the sidebar, select SSH and GPG keys
  5. Click New SSH key
  6. Set a title (e.g., "Work Laptop - Windows 11")
  7. Paste your key into the Key field
  8. Click Add SSH key

Step 5: Test Your SSH Connection

Verify your setup:

ssh -T git@github.com

Expected output:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If you see "access denied" or similar errors, see the troubleshooting section.


Step 6: Troubleshooting

  • Access denied or permission errors
  • Double-check you added the correct public key to GitHub.
  • Ensure ssh-agent is running and your key is added (ssh-add -l shows loaded keys).
  • Make sure you are copying the .pub file, not the private key!

  • Multiple keys or custom key names

  • If you have several keys, specify which key to use by editing (or creating) an SSH config file:

    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/github_ed25519
      AddKeysToAgent yes
    
    Save as ~/.ssh/config.

  • Permission denied (publickey)

  • Ensure your key file permissions are correct:

    chmod 600 ~/.ssh/id_ed25519
    chmod 600 ~/.ssh/id_ed25519.pub
    

  • Agent not starting / Windows issues

  • Restart your computer.
  • Make sure you’re using compatible terminals (latest PowerShell, Git Bash).

References


Security Reminder:
Never share your private SSH key! Always keep it secure and backed up.