Posted on :: Tags: , , ,

I have multiple GitHub accounts, and some of these are collaborators on others. I don’t like to enter my password every time I push, so I set up SSH keys for my accounts. However, GitHub (understandably) doesn’t accept the same key for more than one account. (Otherwise, how would it know which account is being used?)

Fortunately, there is a way to use the ~/.ssh/config file to specify different keys for different target URLs.

# Personal account - the default config
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa

# Work Account
Host work.github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_work

Now you can create another SSH key in ~/.ssh/id_rsa_work and add it to your work account. When you configure a repository, you need to specify git@work.github.com:user/repo.git as the repository address rather than git@github.com:user/repo.git.