22 December 2014

Using multiple accounts with Github

If you're like me and have a personal Github account but work for a company that also uses Github you will probably want to be able to set up multiple accounts on Github.

It's pretty simple to do so:

Firstly you need to create a new key for your company account.

Make sure that you save it to a file other than the default id_rsa otherwise you'll overwrite your default ssh key.

For illustration lets save it to ~/.ssh/id_rsa_alternate

 ssh-keygen -t rsa -C "your-email-address"  

Now open up your company account on Github and navigate through the settings to manage your ssh keys.  Use the following command:

 cat ~/.ssh/id_rsa_alternate.pub  

Copy and paste the output into a new key on your company Github account.

Next we add the new key to our identity:

 ssh-add ~/.ssh/id_rsa_alternate

Edit (or touch) your ssh config file at ~/.ssh/config and include a new option for authenticating using your company account:

  Host github-COMPANY   
  HostName github.com  
  User git  
  IdentityFile ~/.ssh/id_rsa_alternate  

Now you can add a remote like this one:

 git remote add origin git@github-COMPANY:Company/testing.git  

Note that instead of using git@github.com you're using the host name you set up in your ssh config.
Tip