Skip to content

Instantly share code, notes, and snippets.

@moosetraveller
Created August 12, 2021 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moosetraveller/2ae993107cf6ddca0f08f7db01714792 to your computer and use it in GitHub Desktop.
Save moosetraveller/2ae993107cf6ddca0f08f7db01714792 to your computer and use it in GitHub Desktop.
How to use multiple SSH keys

How to use multiple SSH keys

Note: Replace USER_NAME with your username.

Create SSH Key

In this scenario we assume that we use two different GIT repos:

  1. Run ssh-keygen -t rsa -C "name@domain.com"
  2. Enter file name (and path), e.g. C:\Users\USER_NAME\.ssh\id_rsa_github
  3. Type in a passphrase (use a secure, long passphrase)
  4. Confirm passphrase
  5. Re-do step 1 to 4 for id_rsa_azure

Export public key

If you have cygwin installed:

  1. clip < C:\Users\USER_NAME\.ssh\id_rsa_github (for the GitHub RSA public key)
  2. Paste it in the GitHub settings, do the same for the Azure environment

Otherwise:

  1. Open C:\Users\USER_NAME\.ssh\id_rsa_github.pub with an editor
  2. Select all content and copy/paste it in the GitHub settings, do the same for the Azure environment

Define which RSA key is used for which GIT repo

  1. Open C:\Users\USER_NAME\.ssh\config with an editor
  2. Add following lines:
Host github.com
 HostName github.com
 IdentityFile C:\Users\USER_NAME\.ssh\id_rsa_github
 
Host ssh.dev.azure.com
 HostName ssh.dev.azure.com
 IdentityFile C:\Users\USER_NAME\.ssh\id_rsa_azure
  1. Done

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment