Manage SSH Keys for Windows Users

GitHub official tutorials are not clear enough for managing more than one Secure Shell (SSH) key. I am writing this article to provide you with more info on how to handle more than one SSH key.

By Hanno Zhuan

You might finish reading in 3 minutes

Check existing SSH keys

  1. Open File Explorer.
  2. Access your Local Disk.
  3. Open the Users folder.
  4. Open your profile folder.
  5. Open the .ssh folder.

You can also use Git Bash to check existing SSH keys. Run the following command:

ls -al ~/.ssh

If you do not find the .ssh folder or do not see any files—like id_ed25519 and id_ed25519.pub—you do not have any keys yet.

Generate your first SSH key

Follow these steps:

  1. Open Git Bash.
  2. Type the following command and type your GitHub email address:
    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  3. Press Enter when prompted the following:
    > Enter file in which to save the key (/c/Users/YOU/.ssh/id_ed25519): [Press enter]
    
  4. To leave the passphrase empty for easy use, press Enter.
    > Enter passphrase (empty for no passphrase): [Press Enter]
    > Enter same passphrase again: [Press Enter]
    

Connect your SSH key to your GitHub account

Follow these steps:

  1. Open Git Bash.
  2. Copy your SSH public key.
    clip < ~/.ssh/id_ed25519.pub
    
  3. Open your browser.
  4. Open your SSH and GPG keys page.
  5. Add new SSH key.
  6. Fill the title input with Personal.
  7. Leave the Key type to be Authentication key.
  8. Paste your SSH public key in the Key text area.
  9. Add your new key.
  10. Type your GitHub's password.

To test whether you can connect your SSH key with GitHub, follow these steps:

  1. Open Git Bash.
  2. Run the following command:
    ssh -T git@github.com
    
  3. After you run it, you get the following:
    Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
    

Generate another SSH key

Follow these steps:

  1. Open Git Bash.

  2. Type the following command and type your GitHub email address:

    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  3. Change the filename without any extension.

    > Enter file in which to save the key (/c/Users/YOU/.ssh/id_ed25519): [Type custom filename]
    
  4. To leave the passphrase empty for easy use, press Enter key:

    > Enter passphrase (empty for no passphrase): [Press Enter]
    > Enter same passphrase again: [Press Enter]
    
  5. Open File Explorer.

  6. Go to C:\Users\YOU\.

    YOU refers to your profile name.

  7. Find the custom filename you have typed before.

    If your custom filename is jack, find jack and jack.pub.

  8. Copy both files to the .ssh folder.

Repeat the above steps to make as many SSH keys as you like.

Connect another SSH key

  1. Open Git Bash.
  2. Copy your new SSH public key.
    clip < ~/.ssh/jack.pub
    
  3. Open your browser.
  4. Open your SSH and GPG keys page.
  5. Add new SSH key.
  6. Fill the title input with Work.
  7. Leave the Key type to be Authentication key.
  8. Paste your SSH public key in the Key text area.
  9. Add your new key.
  10. Type your GitHub's password.

To test whether you can connect your SSH key with GitHub, follow these steps:

  1. Open Git Bash.
  2. Run the following command:
    ssh -i ~/.ssh/jack -T git@github.com
    
    Notice that this command refers to a specific SSH key.
  3. After you run it, you get the following:
    Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
    

Connect the local Git repository to a specific SSH key

  1. Open a local Git repository.
  2. Run the following command:
    git config --local core.sshCommand "ssh -i ~/.ssh/CUSTOM_KEY"
    
    Do not add .pub.

You can do the same without using the Git command by using your text editor.

  1. Open File Explorer.
  2. Open a local Git repository.
  3. Open the .git folder inside your working directory.
  4. Open the config file with Notepad.
  5. Add sshCommand= "ssh -i ~/.ssh/CUSTOM_KEY" inside [core].
  6. Save the file.

To test this, make local changes and push them to a remote repository.