Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple SSH keys GitHub setup

Multiple SSH Keys settings for different github account

create different public key

Make sure you have .ssh folder created:

$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com" -f "key-name"

Please refer to github ssh issues for common problems.

for example, 2 keys created at:

~/.ssh/id_rsa_github
~/.ssh/id_rsa_bitbucket

then, add these two keys as following

Make sure that the ssh-agent is running:

eval `ssh-agent`
$ ssh-add ~/.ssh/id_rsa_github
$ ssh-add ~/.ssh/id_rsa_bitbucket

you can delete all cached keys before

$ ssh-add -D

finally, you can check your saved keys

$ ssh-add -l

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ subl -a config

Then added

# GitHub account
Host github.com-activehacker
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_github

# Bitbucket account
Host github.com-jexchan
	HostName bitbucket.com
	User git
	IdentityFile ~/.ssh/id_rsa_bitbucket

Setup the SSH in the service of your choice:

After that, check if everything is ok:

  • GitHub: ssh -T git@github.com
  • Bitbuket: ssh -T git@bitbucket.org

Clone you repo and modify your Git config

clone your repo git clone git@github.com:activehacker/gfs.git project

cd project and modify git config

$ git config user.name "foo"
$ git config user.email "foo@email.com" 

or you can have global git config $ git config --global user.name "foo" $ git config --global user.email "foo@gmail.com"

you are now ready to pull, commit, push :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.