git - 我可以让 SSH ForwardAgent 和 ProxyJump 与 Git 一起工作吗?

标签 git ssh ssh-agent

我有两台电脑;我的工作站和我用来运行公司 VPN 的笔记本电脑。我需要通过 VPN 才能访问我的 Git 远程 (BitBucket)。

我的工作站上运行着一个 SSH 代理,其中包含连接到 Git 远程服务器所需的 SSH key 。我已将 SSH 配置为在连接到我的笔记本电脑时转发我的 SSH 代理:

Host my-laptop
    ForwardAgent yes

如果我使用 SSH 连接到我的笔记本电脑,我可以成功 git pull,并且 ssh-agent -l 确认 SSH 代理已正确转发。到目前为止一切顺利!

这就是挑战:我想直接从我的工作站使用 git。这应该可以通过将 SSH 配置为通过我的笔记本电脑进行代理来实现。我的 git Remote 看起来像这样:

➜ git remote -v
origin  ssh://git@bitbucket.my-company.com:7999/my-team/my-project.git (fetch)
origin  ssh://git@bitbucket.my-company.com:7999/my-team/my-project.git (push)

所以我添加了这个 SSH 配置:

Host *.my-company.com
    ProxyJump my-laptop

代理跳转成功了,因为现在我到达了 Git 远程! 🎉

但是,身份验证失败:

git@bitbucket.my-company.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
exit status 128

那么显然 SSH 代理转发在代理命令时不起作用..?

我尝试过的故障排除步骤:

  • 使用 SSH 连接到笔记本电脑并运行 git pull - 它有效

  • 直接从笔记本电脑运行 git pull - 它有效

  • 添加 IdentityFileIdentitiesOnly 以强制使用正确的 key ,但没有任何区别:

    Host *.my-company.com
        ProxyJump my-laptop
        IdentityFile ~/.ssh/hubro@my-company.com.key
        IdentitiesOnly yes
    
  • 在连接到 Git 远程主机时添加 ForwardAgent yes,没有任何区别:

    Host *.my-company.com
        ProxyJump my-laptop
        ForwardAgent yes
        IdentityFile ~/.ssh/hubro@my-company.com.key
        IdentitiesOnly yes
    

那么为什么在运行 git 命令时没有使用我的本地 SSH 代理?

最佳答案

事实证明,在此设置中我什至不需要 SSH 代理转发,因为 ProxyJump 设置设置了一个隧道,让我的工作站“直接”与 git 远程通信。

我收到“Permission denied (publickey)”错误的原因原来是我的发行版 (Arch) 是最新的并且默认情况下已经禁用了对“ssh-rsa” key 的支持。 (在撰写本文时,Arch Linux 附带 openssh 8.8p1)

令人沮丧的是,我使用“rsa-sha2-512”生成我的 key 并不重要,它应该是安全的,我的 SSH 客户端仍然没有它。

但是,我使用 ed25519 生成了一个新 key ,这解决了我的问题。

$ ssh-keygen -t ed25519

关于git - 我可以让 SSH ForwardAgent 和 ProxyJump 与 Git 一起工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69583644/

相关文章:

xcode - 无意中出现两个主分支 Git

vb.net - SSHAuthenticationExcetion :No suitable authentication method found to complete authentication

ssh - 将证书添加到 ssh-agent 以获取已在代理内部的 key

java - 从 java 执行的 rsync 返回文件未找到错误

git - 代码构建将 Artifact 推回 github 的问题

没有 ssh-add 的 ssh key 转发

git - 可视化git日志树时如何指定最左边(感兴趣的主要分支)?

git - 我可以在存储库中指定 .git/config 值吗

github.io root 不会自动渲染index.html

ssh - Phpstorm 9 ssh session 身份验证取消