black flat screen computer monitor

Managing multiple ssh identities for git projects

Sometimes we need to use different hosts for our projects. This can be as simple as trying to maintain different SSH keys for work and personal use. Github currently enforces to not use the same SSH key for different accounts. I was a little confused about how to go about this, and the result of which is this small note. We can configure SSH to match particular SSH identities with specific hostnames.

This is my current ssh config:

User USER1
IdentityFile ~/.ssh/id_rsa

Host WEBSITE1
  HostName example.com
  User marypoppins

Host WEBSITE2
  HostName example2.com
  User rodreiss

Host WEBSITE3
  HostName example3.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_web3

As you can see, for WEBSITE3 I am using a seperate identity file. This way I can maintain multiple SSH identities!

Usage in a project

Now once you have updated your ssh configuration, all you have to do now to use this new ssh key on a different project is modify your git remote URL.

git remote set-url origin git@HOST:username/repository.git

I hope you like this small tip! 😊

en_USEnglish