【问题标题】:How to get git to use an ssh (rsh) transport other than "ssh"如何让 git 使用“ssh”以外的 ssh (rsh) 传输
【发布时间】:2012-09-07 18:59:12
【问题描述】:

是否可以让 git 使用“ssh”以外的东西作为 ssh 程序?为此,rsync 有一个 -e 选项,以及可以将 rsh 或 ssh 用作传输的其他接口。我的特定用例是通过堡垒主机链接 ssh 连接,因为防火墙不允许直接 ssh 访问我从中克隆/拉取的主机。

到目前为止,我想出的最佳解决方案是创建一个目录,其中包含一个名为“ssh”的可执行文件,并将该目录放在我的 PATH 开头。 “ssh”文件的内容是:

#!/bin/sh
# If we were being clever we'd look at where we were and just snip that
# off the path.
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
exec ssh bastion.example.org ssh "$@"

这可行,但该方法有许多缺点。

请注意,GIT_SSH 环境变量并不能满足我的要求,因为您仍然需要创建一个脚本并引用它。而使用 rysnc 的 -e 选项我可以做到

rsync -e 'ssh -K bastion.example.org ssh' ...

【问题讨论】:

    标签: git ssh rsync rsh


    【解决方案1】:

    您可以自己配置 ssh,而不是尝试将 git 配置为使用其他程序:

    ~/.ssh/config 文件中,添加一个新的Host 部分

    Host git.example.org
      Username myusername
      ProxyCommand ssh bastion.example.org "nc git.example.org 22"
    

    然后,您只需将遥控器指向“git.example.org”主机。

    另外,如果你使用 OpenSSH >= 5.4 并且不想依赖服务器上的 netcat,你可以使用 SSH 的 netcat mode 代替:

    Host git.example.org
      Username myusername
      ProxyCommand ssh bastion.example.org -W "git.example.org:22"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 2021-11-29
      • 1970-01-01
      • 2021-06-06
      相关资源
      最近更新 更多