How to handle multiple github accounts

I’ve always just worked with one GitHub account (my personal one), and then came octopress. I wanted to convert all the sites I manage from WordPress to octopress. Everything went well until running rake deploy.

Step 1: Create a new SSH key

I had to generate a new SSH key for the second GitHub account.

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

Be sure not to over-write your existing key (~/.ssh/id_rsa). I named mine id_rsa_ACCOUNT.

Step 2: Attach the new key to the GitHub Account.

I’m not going to go into any details here, it should be pretty obvious what you need to do.

Step 3: Create a config file

This config file is where all the magic happens. This is what allows you to specify which account to use when pushing things to GitHub.

touch ~/.ssh/config
vim ~/.ssh/config

Add the following to the file

  User git
  IdentityFile ~/.ssh/id_rsa

Host github-ACCOUNT
  User git
  IdentityFile ~/.ssh/id_rsa_ACCOUNT

Step 4: Testing

Now when pushing to your different accounts you can specify which one.


git remote add origin git@github-ACCOUNT:username/repo.git
git push origin master