gpt4 book ai didi

git - 如何让 git 使用 "ssh"以外的 ssh (rsh) 传输

转载 作者:行者123 更新时间:2023-12-02 13:58:26 24 4
gpt4 key购买 nike

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

到目前为止,我想出的最佳解决方案是创建一个目录,其中包含一个名为“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' ...

最佳答案

您可以配置 ssh 本身,而不是尝试将 git 配置为使用另一个程序:

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

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

然后,您只需将 Remote 指向“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"

关于git - 如何让 git 使用 "ssh"以外的 ssh (rsh) 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12427440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com