DEV Community


Discussion on: How to Manage Multiple SSH Key Pairs

ttntm profile image
Tom Doe

Thanks for this article, sure it'll help some folks get into SSH.

One thing that I had issues with was using multiple GitHub keys on one machine. This can happen if you have an older personal account and a newly added account for work for example.

What helped me sorting it out was a bit harder to find that I would have thought, so I made a note re: cloning a repository using a specific SSH identity:

git clone -c core.sshCommand="/usr/bin/ssh -i /home/me/.ssh/id_rsa_foo"
Enter fullscreen mode Exit fullscreen mode

Leaving a link to my note here just in case anyone's looking for further details and context:

armyofda12mnkeys profile image
armyofda12mnkeys • Edited

Note I have a personal github and a work github account... and I used something like this instead:

//personal account for, note can also choose to leave this as 'Host' if dont' have other keys and want this to be the default
Host github-my_personal_username
User git
IdentityFile ~/.ssh/id_rsa-github-my_personal_username
// IdentitiesOnly yes

//work account for
Host github-my_work_username
User git
IdentityFile ~/.ssh/id_rsa-github-my_work_username
// IdentitiesOnly yes

and just change the clone url slight when needed:
$ git clone git@github-my_work_username:me/repo.git

Forem Open with the Forem app