Skip to content

Instantly share code, notes, and snippets.

@tr4nk
Forked from jexchan/multiple_ssh_setting.md
Last active October 3, 2019 15:30
Show Gist options
  • Save tr4nk/2ddd452a646c7944c75ceddf3e0b3b12 to your computer and use it in GitHub Desktop.
Save tr4nk/2ddd452a646c7944c75ceddf3e0b3b12 to your computer and use it in GitHub Desktop.
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key:

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

for example, 2 keys created at:

~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan

add the public key to github account: https://github.com/settings/keys

start ssh-agent in the background eval $(ssh-agent -s)

then, add these two keys as following

$ ssh-add ~/.ssh/id_rsa_activehacker
$ ssh-add ~/.ssh/id_rsa_jexchan

finally, you can check your saved keys

$ ssh-add -l

Modify the ssh config

$ code ~/.ssh/config

Then added

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

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

Clone you repo and modify your Git config

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

cd gfs_jexchan and modify .git/config

[user]
	name = activehacker
	email = your_email@youremail.com
[remote "origin"]
	url = git@github.com:activehacker/gfs.git

Ref: https://help.github.com/en/articles/connecting-to-github-with-ssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment