gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:54:44 27 4
gpt4 key购买 nike

我有两台电脑;我的工作站和我用来运行公司 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com