论证" -i"传递给GIT_SSH_COMMAND被忽略了

时间:2018-02-20 05:02:55

标签: git ssh public-key-encryption

我想将其他IdentityFile用于git。我想动态地使用它,而不是通过配置。我这样做:

  $ 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.

pub键" id_ed25519.pub"在我的bitbucket。

这也失败了:

  $ 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.

$ git remote -v
origin  git@bitbucket.org:company123/repo456.git (fetch)
origin  git@bitbucket.org:company123/repo456.git (push)

" -v" 添加到' ssh -i /home/my_user/.ssh/id_ed25519' 显示正在使用我的RSA密钥,而不是ED。为什么呢?

3 个答案:

答案 0 :(得分:2)

检查命令(直接调用git或通过别名调用)和配置:
正如我在“Using GIT_SSH_COMMAND”中提到的,git config -l可能会显示其他会覆盖环境变量的配置。

检查git config core.sshCommand的返回。

最后,GIT_SSH_COMMAND表示Git 2.10+,所以如果你的Git版本太旧,你需要先更新它。

答案 1 :(得分:0)

最近的Ubuntu版本存在相同的问题:

使用-vvv显示以下内容:

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

添加-o IdentitiesOnly=yes即可解决。

完整的git命令:

GIT_SSH_COMMAND='ssh -o IdentitiesOnly=yes -i /home/ubuntu/code/id_rsa -F /dev/null' git pull

答案 2 :(得分:0)

如果有人在将 GIT_SSH_COMMAND 设置在一行上,然后在另一行实际运行 git 命令的细微变化时遇到此问题,请尝试以下之一:

  1. 在同一行设置 GIT_SSH_COMMAND
$ GIT_SSH_COMMAND="ssh -i ${key_location}" git clone [...]

或....

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

我在找到要使用的键后立即设置 GIT_SSH_COMMAND,然后在几行之后运行 git。我错误地删除了 export,它破坏了 git 命令。


由于这是搜索“GIT_SSH_COMMAND”时最热门的谷歌链接之一,并且问题比答案更受欢迎,可能是某些访问者遇到与 OP 相同的问题,但原因与其他答案不同推荐。希望这对某人有帮助。