I've realized over the past few months that the ssh's command flag "-i" (which refers to specify an identity file) doesn't work properly when I try to authenticate to some server.
From what I understood, I could use this flag to specify an ssh key to authenticate to the server, avoiding the need to test over each key added to my agent and possibly overflow the connection attempts.
What I'm trying now is to change the user to authenticate to git (the question is not git specific), and what is happening is this:
- I have two ssh keys that authenticate to github, let's call them user1.pem and user2.pem.
- user1.pem authenticates to user1 in github and user2.pem authenticates to user2.
- I run the command "ssh -T [email protected]", it authenticates to user1.
- I run the command "ssh -T -i ~/.ssh/user2.pem [email protected]", it continues to authenticate to user1.
There's no problem at all with the keys, both have been added to the agent and they have the correct file permissions.
To circumvent this I had to remove all the keys from my agent and re-add only the user2.pem, then it authenticated to user2.
Just to reiterate, this is NOT git specific, as I had this problem with common linux servers as well, and I couldn't find any solution besides configuring the hosts in the ~/.ssh/config
file. I'm using git as example just because it is easier to test.
Am I using "ssh -i" flag in the wrong way?
ssh ... [email protected]
, it authenticates as usergit
, not as useruser1
.