如何让git使用除“ssh”之外的ssh(rsh)传输

时间:2012-09-14 15:20:11

标签: git ssh rsync rsh

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

1 个答案:

答案 0 :(得分: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 mode代替:

Host git.example.org
  Username myusername
  ProxyCommand ssh bastion.example.org -W "git.example.org:22"
相关问题