[英]The argument “-i” passed to GIT_SSH_COMMAND is being ignored
I want to use other IdentityFile for git.我想为 git 使用其他 IdentityFile。 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. pub 密钥“id_ed25519.pub”在我的 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.将“-v”添加到'ssh -i /home/my_user/.ssh/id_ed25519'表明正在使用我的RSA密钥,而不是ED。 Why?为什么?
I had the same issue with the recent Ubuntu version:我最近的 Ubuntu 版本也有同样的问题:
Using -vvv revealed following:使用 -vvv 显示以下内容:
debug2: key: /home/ubuntu/.ssh/id_rsa (0x5628e48246d0), agent
debug2: key: /home/ubuntu/code/id_rsa (0x5628e4820af0), explicit
Adding -o IdentitiesOnly=yes
solved it.添加-o IdentitiesOnly=yes
解决了它。
Full git
command:完整的git
命令:
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:检查您的命令(是直接调用 git 还是通过别名调用)和配置:
As I mention in " Using GIT_SSH_COMMAND
", a git config -l might reveal other configuration that would override the environment variable.正如我在“使用GIT_SSH_COMMAND
”中提到的, git config -l 可能会显示其他会覆盖环境变量的配置。
Check the return of git config core.sshCommand
.检查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.最后, GIT_SSH_COMMAND
表示 Git 2.10+,所以如果你的 Git 版本太旧,你需要先更新它。
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:如果有人在GIT_SSH_COMMAND
上设置GIT_SSH_COMMAND
时遇到此问题,然后在另一行上实际运行git
命令,请尝试以下操作之一:
GIT_SSH_COMMAND
on the same line:在同一行设置GIT_SSH_COMMAND
:$ GIT_SSH_COMMAND="ssh -i ${key_location}" git clone [...]
or....或者……
GIT_SSH_COMMAND
导出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.我在找到要使用的密钥后立即设置GIT_SSH_COMMAND
,然后在几行之后运行git
。 I mistakenly removed the export
and it broke the git
command.我错误地删除了export
并破坏了git
命令。
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.由于这是搜索“GIT_SSH_COMMAND”时最热门的 google 链接之一,并且该问题比答案更受欢迎,因此可能是某些访问者遇到了与 OP 相同的问题,但原因与其他答案推荐的原因不同。 Hopefully this is helpful for someone.希望这对某人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.