You can use multiple github SSH keys in the same environment
I have 2 github accounts. My work account and my personal account. In the past, i’ve had trouble working with both accounts on one laptop. This is mainly because my personal account has an old SSH-key created on a different laptop.
I don’t want to add both SSH keys to both accounts on github, so on my work laptop, i used to use HTTPS git with my personal account and SSH git with my work account. This got super annoying so i figured out how to use multiple git-ssh keys on one environment.
Basically, you need both ssh keys, and a modified ssh config.
assuming i have 2 ssh keys, one for work, and one for personal…
- Personal key:
- Work key:
… this is my
Host github-work HostName github.com AddKeysToAgent yes UseKeychain yes User git IdentityFile ~/.ssh/id_work Host github-personal HostName github.com AddKeysToAgent yes UseKeychain yes User git IdentityFile ~/.ssh/id_personal
# cloning using your personal account $ git clone git@github-personal:personalandy/project.git $ cd project $ git config user.name personalandy $ git config user.email email@example.com
… or you can use
ssh:// prototol, which skips the
# cloning using your work account $ git clone ssh://github-work/workandy/project.git $ cd project $ git config user.name workandy $ git config user.email firstname.lastname@example.org