Create different ssh key according the article Generating SSH keys.
Example:
$ ssh-keygen -t rsa -C "[email protected]" -f id_rsa_personalOr for your work account:
$ ssh-keygen -t rsa -C "[email protected]" -f id_rsa_workFor example, 2 keys created at:
~/.ssh/id_rsa_work
~/.ssh/id_rsa_personalThen, add these two keys as following:
$ ssh-add ~/.ssh/id_rsa_work
$ ssh-add ~/.ssh/id_rsa_personalYou can delete all cached keys before:
$ ssh-add -DFinally, check your saved keys:
$ ssh-add -lRemember to add created keys to your Github account. This guide will help you.
Open ~/.ssh/config file:
$ cd ~/.ssh/
$ touch config
$ vim config # please use your favorite editorThen add something like:
# work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
# personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
Finally, test your added hosts:
$ ssh -T [email protected]
Hi WorkUser! You've successfully authenticated, but GitHub does not provide shell access.
Or:
$ ssh -T [email protected]
Hi PersonalUser! You've successfully authenticated, but GitHub does not provide shell access.
Clone your repo using a configured host (in this case, "github.com-personal"):
git clone [email protected]:repoowner/repo.gitEnter repository and modify git config:
$ git config user.name "personal"
$ git config user.email "[email protected]" Done!