简体   繁体   中英

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  git@bitbucket.org:company123/repo456.git (fetch)
origin  git@bitbucket.org: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?

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

Check you commands (is git called directly or through an alias) and configuration:
As I mention in " Using GIT_SSH_COMMAND ", a git config -l might reveal other configuration that would override the environment variable.

Check the return of git config core.sshCommand .

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

In case anyone is having this problem with the slight variation of setting GIT_SSH_COMMAND on one line, and then on a different line actually running the git command, please try one of the following:

  1. set GIT_SSH_COMMAND on the same line:
$ GIT_SSH_COMMAND="ssh -i ${key_location}" git clone [...]

or....

  1. export GIT_SSH_COMMAND
$ export GIT_SSH_COMMAND="ssh -i ${key_location}"
$ git clone [...]

I was setting GIT_SSH_COMMAND right after finding which key to use, and then running git a few lines later. I mistakenly removed the export and it broke the git command.


Since this is one of the top google links when searching for "GIT_SSH_COMMAND" and the question is more upvoted than the answers, it might be that some visitors have the same problem as OP but for a different reason than what the other answers recommend. Hopefully this is helpful for someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM