Create different ssh key according the article Generating SSH keys.
Example:
$ ssh-keygen -t rsa -C "[email protected]" -f id_rsa_personal
Or for your work account:
$ ssh-keygen -t rsa -C "[email protected]" -f id_rsa_work
For example, 2 keys created at:
~/.ssh/id_rsa_work
~/.ssh/id_rsa_personal
Then, add these two keys as following:
$ ssh-add ~/.ssh/id_rsa_work
$ ssh-add ~/.ssh/id_rsa_personal
You can delete all cached keys before:
$ ssh-add -D
Finally, check your saved keys:
$ ssh-add -l
Remember 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 editor
Then 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.git
Enter repository and modify git config:
$ git config user.name "personal"
$ git config user.email "[email protected]"
Done!