Reputation: 93
I am using an ec2 server in which there are two users. Let's call them user1 and user2 with their separate user1key and user2key in the ~/.ssh folder.
My git config file in the ~/.ssh folder looks like this
Host user1
HostName github.com
IdentityFile ~/.ssh/user1key
Host user2
HostName github.com
IdentityFile ~/.ssh/user2key
I want to use user1 to pull and commit changes to the origin. However, when I run git pull
, it asks for the passphrase of user2key which I don't have.
I tried using git config user.name "user1"
inside the repository and then did a git pull
but it again asked for a passphrase for user2key.
I even tried removing the information for user2 from the config file and run git pull
again but it still asked for the passphrase for user2key.
Upvotes: 1
Views: 870
Reputation: 1323553
user.name
has nothing to do with authentication to the remote server.
If you are using a ~/.ssh/config with a Host entry named user1, then your remote URL must become:
git@user1:user1/repo-name
And you can test the connection to github.com
with ssh -Tv user1
.
Again, the name of the Host entry is what you need to use for your URL.
It becomes a shortcut for
ssh -i ~/.ssh/user1key -Tv [email protected]
Note: add User git
in each Host
subsection, that way you do not even have to specify git@
.
Host user1
HostName github.com
User git
IdentityFile ~/.ssh/user1key
Host user2
HostName github.com
User git
IdentityFile ~/.ssh/user2key
Upvotes: 1