May 31, 2017

Using Two Different GitHub Accounts on the same Computer

Some days ago I created next to my private GitHub account another one for work. At first I was a bit confused how to authenticate to two different GitHub accounts. The solution is rather simple as my former colleague R. H. told me. At first, you need to create two different SSH keys id_rsa_work and id_rsa_priv. Of cause you can use your already existing SSH key for one of the GitHub accounts. Then, the public portion must be deposited in the respective GitHub account.

Now, you need to add something like this to your ~/.ssh/config:

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

#Uni GitHub
Host github-private
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_priv
...

Done.

When you check out a git for private usage, you do something like git clone git@github-private:user/repo.git, for a git you use for work git clone git@github-work:otheruser/otherrepo.git. Easy as cake.

© holger 2015 - 2020 |