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.

1
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.

1
2
touch ~/.ssh/config
vim ~/.ssh/config

Add the following to the file

1
2
3
4
5
6
7
8
9
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

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

Step 3: Testing

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

Example:

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

Comments