Wednesday, February 20, 2013

Multiple github accounts on one computer

Generate a key

ssh-keygen -t rsa -C "your-email-address"
Save this key in a different file than the default. e.g. ~/.ssh/id_rsa_TWO.pub

Attach keys

Login to your second GitHub account and attach the newly created key  (~/.ssh/id_rsa_TWO.pub) . On Github this should be under the Account Settings -> SSH Keys.

Next, because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal, type: ssh-add ~/.ssh/id_rsa_TWO. If successful, you’ll see a response of “Identity Added.”

Create SSH configs

Create and ssh config file under ~/.ssh/config
  1 #Default Github
  2 Host github.com
  3     HostName github.com
  4     User git
  5     IdentityFile ~/.ssh/id_rsa
  6
  7 Host github-TWO
  8     HostName github.com
  9     User git
 10     IdentityFile ~/.ssh/id_rsa_TWO

Create a repository

Create a repo on github using the add repo button

Now for using the 2nd user do the following:
In the directory you wish to push to github:
  $ git init
  $ git remote add origin git@github-TWO:USER/remoterepo.git
  $ git add .
  $ git commit -m "initial commit."
  $ git push origin master


No comments: