2

是否有可能让 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' ...
4

1 回答 1

2

您可以配置 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 模式来代替:

Host git.example.org
  Username myusername
  ProxyCommand ssh bastion.example.org -W "git.example.org:22"
于 2012-10-02T19:11:24.240 回答