Skip to content

Instantly share code, notes, and snippets.

@khoatran
Last active May 5, 2016 07:52
Show Gist options
  • Save khoatran/9fb612cdfd3fa4ee6612e79d70b55fc6 to your computer and use it in GitHub Desktop.
Save khoatran/9fb612cdfd3fa4ee6612e79d70b55fc6 to your computer and use it in GitHub Desktop.
Multiple SSH Keys settings for different git account

Multiple SSH Keys settings for different git account

Create different public key

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

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

For example, 2 keys created at:

~/.ssh/id_rsa_acc_a
~/.ssh/id_rsa_acc_b

then, add these two keys as following

$ ssh-add ~/.ssh/id_rsa_acc_a
$ ssh-add ~/.ssh/id_rsa_acc_b

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
$ vim config

Then added

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

#jexchan account
Host github.com-id_rsa_acc_b
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_acc_b

You can also modify the hostname in case you have another git repos host (not just github)

Clone you repo and modify your Git config

clone your repo and modify git config in each cloned folder. git clone git@github.com:gitaccount/gfs.git repository_name

cd repository_name and modify git config

$ git config user.name "any user name you want"
$ git config user.email "your email that used for this repos commit and push" 

or you can have global git config $ git config --global user.name "any user name you want" $ git config --global user.email "your global email"

then use normal flow to push your code

$ git add .
$ git commit -m "your comments"
$ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment