传递给GIT_SSH_COMMAND的参数“-i”被忽略

问题描述 投票:4回答:2

我想将其他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  [email protected]:company123/repo456.git (fetch)
origin  [email protected]:company123/repo456.git (push)

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

git ssh public-key-encryption
2个回答
3
投票

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

检查git config core.sshCommand的返回。

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


1
投票

我最近的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
© www.soinside.com 2019 - 2024. All rights reserved.