You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为已有Git仓库添加需SSH跳转代理的远程仓库?

问题描述

本地Git仓库已配置origin远程仓库,想要添加另一台名为remote1的机器作为新远程仓库,执行了以下命令:

git remote add remote1
git remote set-url remote1 ssh://sshUser@remote1Address:path/to/.git

但执行git push remote1 branchName时出现连接超时错误:

ssh: connect to host remote1Address port 22: Connection timed out.

由于remote1的22端口关闭,必须通过跳转代理才能SSH访问,.ssh/config配置如下:

Host jumpProxy
    Hostname jumpProxyAddress
    User jumpUser

Host remote1
    Hostname remote1Address
    User sshUser
    ProxyJump jumpUser@jumpProxyAddress

推测Git未读取.ssh/config配置,未调用跳转代理,寻求解决办法。

解决办法
  • 修改远程仓库URL为.ssh/config中的Host别名
    把remote1的远程URL改成使用配置里定义的remote1别名,而非直接写IP/域名:

    git remote set-url remote1 ssh://remote1/path/to/.git
    

    这样Git调用SSH时,SSH会自动读取.ssh/config里的remote1配置,走跳转代理连接。

  • 先验证SSH连接是否正常
    单独测试SSH连接remote1,确认配置生效:

    ssh remote1
    

    如果能成功登录,说明SSH配置没问题,再执行Git推送即可。

  • 检查Git使用的SSH路径
    部分环境中Git可能未使用系统默认SSH,可查看当前Git的SSH命令:

    git config --get core.sshCommand
    

    若输出为空或路径不对,设置为系统默认SSH路径:

    # Linux/macOS
    git config --global core.sshCommand /usr/bin/ssh
    # Windows
    git config --global core.sshCommand C:\Windows\System32\OpenSSH\ssh.exe
    

内容的提问来源于stack exchange,提问作者Naghi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 12:25:22