I've set up two GitHub accounts, but I can't get ssh keys to work correctly. I've tried various configs.
Host github_username1
HostName github.com
IdentityFile ~/.ssh/rsa_1
User username1
Host github_username2
HostName github.com
IdentityFile ~/.ssh/rsa_2
User username2
git push
:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Works for username1:
Host github.com
HostName github.com
IdentityFile ~/.ssh/rsa_1
User username1
Host github.com
HostName github.com
IdentityFile ~/.ssh/rsa_2
User username2
git push
at username2's repo:
ERROR: Permission to username2/repo.git denied to username1.
fatal: The remote end hung up unexpectedly
I've also tried git push
with both IdentityFile
and User
settings under same Host
. The output is the same as with the last config.
I think git automatically searches for Host "github.com" because the remote is such. It is said that Host can be anything you want (https://stackoverflow.com/a/3828682). Is there any way to change what Host from ssh config should specific repo use?
It would be ideal if I could solve this just from ~/.ssh/config.