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