Last Updated: February 25, 2016
·
2.345K
· joakley77

Multiple Git accounts on one box

I recently found myself having to push code to multiple repos. Surprisingly, nobody at work knew how to do this or had any experience with it so I took it upon myself to...search Google.

First, let's open up your flavor of Terminal and create a series of ssh keys. Use a naming scheme that makes them easy to understand and make sure each file uses a different name.

ssh-keygen -t rsa -f ~/.ssh/id_rsa.bitbucket.work -C "yourbitbucket@email.com"

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github.home -C "yourbitbucket@email.com"

You now need to create a ssh config file to store these references:

touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo 'IdentityFile ~/.ssh/id_rsa.bitbucket.work" >> ~/.ssh/config
echo 'IdentityFile ~/.ssh/id_rsa.github.home" >> ~/.ssh/config

Copy your ssh key to clipboard. Change the key filename accordingly.

Mac:
pbcopy < ~/.ssh/id_rsa.bitbucket.work.pub

Ubuntu:
sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_rsa.bitbucket.work.pub

Windows:
clip < ~/.ssh/id_rsa.bitbucket.work.pub

Hop on over to Github/Bitbucket/whatever and add your new ssh key. That's it!

Original credit on how to do this:
http://www.karan.org/blog/index.php/2009/08/25/multiple-ssh-private-keys