git - 传递给 GIT_SSH_COMMAND 的参数 "-i"被忽略

标签 git ssh public-key-encryption

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

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

发布 key “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)

Adding "-v"'ssh -i/home/my_user/.ssh/id_ed25519' 显示我的 RSA key 是被使用,而不是 ED。为什么?

最佳答案

我在使用最新的 Ubuntu 版本时遇到了同样的问题:

使用 -vvv 显示以下内容:

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

添加 -o IdentitiesOnly=yes 解决了它。它告诉 SSH 忽略来自 ssh-agent 的身份(例如,使用 ssh-add 添加)否则优先。

完整的 git 命令:

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

关于git - 传递给 GIT_SSH_COMMAND 的参数 "-i"被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48878177/

相关文章:

C# 我如何进行加密?

Xcode 4 和版本控制——但是哪一个?

linux - WAN 上的 SSH 远程登录失败,但 lan 上的登录可以

ssh - 如何在首次启动时从控制台/在控制台下接受 teamviewer 许可协议(protocol)

linux - 如何在 github 上为 1 个用户的 2 个 repo 添加部署 key

c# - 使用字符串中的公钥验证 JWT

c++ - 公钥完整性 - 中间人攻击

git-svn:有好的分支和 merge 模式吗?

git - 未找到存储库,无法推送到私有(private)存储库

git - 如何查看一个分支中的哪些提交不在另一个分支中?