Multiple github accounts in one computer
Today I've created my second github account after a long time using the service as single user. This account is mostly for professional works in addition to my personal account for open source projects.
I had never had two accounts and was a little lost at first. Here is how I managed my problem (I hope help others):
1. Generate SSH Key for new github user
cd ~/.ssh
ssh-keygen -t rsa -C "user@email.com"
When asked which file write the following:
~/.ssh/id_rsa_githubusername
This will generate two files idrsagithubusername and idrsagithubusername.pub.
You can manually add that to your ssh keys
ssh-add -K id__rsa__githubusername
2. Add new SSH Key to your user on github.com
copy the content of idrsagithubusername.pub:
$ pbcopy < ~/.ssh/id__rsa__githubusername.pub
- go to https://github.com/settings/ssh
- click in ADD SSH KEY button on the right
- paste the content of idrsagithubusername.pub and save it
3. Create SSH config file
$ touch ~/.ssh/config
4. Edit SSH config file with your accounts information
#Default GitHub
Host github-username //name to identify github account
HostName github.com //don't change this
User githubusername //username on github
IdentityFile ~/.ssh/id_rsa_githubusername //ssh key created
5. Cloning repository for the new user
git clone git@github-username:user/repo.git
NOTE: we change github.com with github-username as specified on our SSH config file.