Something strange is happening to me, I have 1 app, in which I have to upload it to 2 different github accounts, however despite the fact that I create the ssh-keygens with different names:
ssh-keygen -t rsa -b 2048 -C "clave1" -f /home/user/.ssh/clave1
ssh-keygen -t rsa -b 2048 -C "clave2" -f /home/user/.ssh/clave2
I can only manage to connect with one github account, since the other gives me a permission error when trying to upload, despite the fact that I have verified on several occasions that the key is the same with the account I want to connect to, until I have pasted it again, I also have my .ssh/config
Host host1
HostName github.com
User git
IdentityFile "~/.ssh/clave1"
Host host2
HostName github.com
User git
IdentityFile "~/.ssh/clave2"
What could be happening? I appreciate any suggestion, maybe I'm missing something, greetings!
I would add both private keys to the authentication agent. It is a much simpler solution and it does not pose a security problem in your particular case since both repositories live on GitHub.
What I recommend does not require editing the SSH configuration file. This way you are telling your SSH client to try both keys when authenticating.
Basically, when connecting to github, any subdomain works. However, by default ssh's behavior is to try all keys, and in your case it will try the first key before the second. That can be prevented by using
IdentitiesOnly yes
. So you~/.ssh/config
would be:And when cloning your repos, you use:
If you already cloned the projects, you can use for example
Or edit by hand your
./.git/config
in each project