我想为 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/