Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The argument "-i" passed to GIT_SSH_COMMAND is being ignored

I want to use other IdentityFile for git. I want to use it dynamically, not via config. I'm doing this:

  $ GIT_SSH_COMMAND='ssh -i /home/my_user/.ssh/id_ed25519' git pull origin master
  repository access denied.
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

The pub key "id_ed25519.pub" is at my bitbucket.

And this fails too:

  $ git pull origin master
  repository access denied.
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

And:

$ git remote -v
origin  [email protected]:company123/repo456.git (fetch)
origin  [email protected]:company123/repo456.git (push)

Adding "-v" to 'ssh -i /home/my_user/.ssh/id_ed25519' reveals that my RSA key is being used, instead of ED. Why?

like image 692
jerry Avatar asked Feb 20 '18 05:02

jerry


People also ask

What is Git_ssh_command?

Finally, GIT_SSH_COMMAND means Git 2.10+, so if your version of Git is too old, you will need to update it first. Follow this answer to receive notifications.

How does Git know which SSH key to use?

Git does not know, or care. It just runs ssh. Specifies that ssh(1) should only use the authentication identity files configured in the ssh_config files, even if ssh-agent(1) or a PKCS11Provider offers more identities. The argument to this keyword must be “yes” or “no”.

Where are git SSH keys stored?

SSH keys are stored in the ~/. ssh folder. You can have more than one key in there, because SSH keys are used for things other than Git.


Video Answer


1 Answers

I had the same issue with the recent Ubuntu version:

Using -vvv revealed following:

debug2: key: /home/ubuntu/.ssh/id_rsa (0x5628e48246d0), agent
debug2: key: /home/ubuntu/code/id_rsa (0x5628e4820af0), explicit

Adding -o IdentitiesOnly=yes solved it.

Full git command:

GIT_SSH_COMMAND='ssh -o IdentitiesOnly=yes -i /home/ubuntu/code/id_rsa -F /dev/null' git pull
like image 156
AlexTG Avatar answered Oct 14 '22 13:10

AlexTG