I'm having some trouble getting two different SSH keys/GitHub accounts to play well together. I have the following setup:
Repos accessible from one account using git@github.com:accountname
Repos accessible from another account using git@github.com:anotheraccount
Each account has its own SSH key. Both SSH keys have been added and I have created a config file. I don't believe the config file is correct though. I'm not quite sure how to specify that repos accessed using git@github.com:accountname
should use id_rsa
and git@github.com:anotheraccount
should use id_rsa_anotheraccount
.
Andy Lester's response is accurate but I found an important extra step I needed to make to get this to work. In trying to get two profiles set up, one for personal and one for work, my ~/.ssh/config
was roughly as follows:
Host me.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/me_rsa
Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/work_rsa
My work profile didn't take until I did a ssh-add ~/.ssh/work_rsa
. After that connections to github used the correct profile. Previously they defaulted to the first public key.
For Could not open a connection to your authentication agent when using ssh-add
,
check:
https://stackoverflow.com/a/17695338/1760313