使用端口转发(SSH 隧道)的 git Push

发布于 2024-11-15 20:17:39 字数 697 浏览 3 评论 0原文

我正在尝试访问托管在防火墙后面的集群上的 GIT 存储库。当我在校园内(位于防火墙后面)时,我可以直接访问集群,并且可以从校园外通过 SSH 连接到特定计算机,然后在需要时通过 ssh 连接到集群。

我尝试使用以下命令设置隧道:

sudo ssh -L 9418:cluster:9418 [email protected]

但我仍然无法从我的机器上运行“git Push”。我知道我错过了一些东西,但无法完全弄清楚。

编辑: 我将 ~/.ssh/config 修改为:

Host cluster
     NoHostAuthenticationForLocalhost  yes
     Hostname localhost
     Port 9418

并在运行 git Push 时出现错误:

ssh_exchange_identification: Connection closed by remote host
fatal: The remote end hung up unexpectedly

I am trying to access a GIT repo that is hosted on a cluster that exists behind a firewall. When I am on campus (which is behind the firewall) I am able to access the cluster directly and I am able to SSH in to a particular machine from off campus and then ssh to the cluster if I need to.

I have tried setting up a tunnel using:

sudo ssh -L 9418:cluster:9418 [email protected]

but I am still not able to run "git push" from my machine. I know I'm missing something but cant quite figure it out.

EDIT:
I modified ~/.ssh/config to have:

Host cluster
     NoHostAuthenticationForLocalhost  yes
     Hostname localhost
     Port 9418

and get errors when I run git push:

ssh_exchange_identification: Connection closed by remote host
fatal: The remote end hung up unexpectedly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚殇 2024-11-22 20:17:39

我猜测 Git 远程 URL 的主机名部分是 cluster,而不是 localhost。 git config remote.origin.url 的输出是什么?如果是这样的:

git://cluster/repo.git

那么将其更改为:

git://localhost/repo.git

ssh 端口转发的工作原理是 ssh 客户端在本地计算机上打开一个端口(在您的情况下为 9418)并侦听连接。每当应用程序连接到该端口时,您的 ssh 客户端都会要求 ssh 服务器(在您的情况下为 ssh.server)打开与隧道远程端(cluster)的连接端口 9418 在你的情况下)。所有发送到本地端口的数据都会通过现有的 ssh 会话转发到 ssh 服务器。然后,ssh 服务器将数据注入到与目标计算机的连接中。因此,从您的角度来看,您正在连接到本地计算机。从目标的角度来看,您正在从 ssh 服务器进行连接。

另外,您的 ssh 配置似乎不正确。该配置告诉您的客户端,每当您想要 ssh 到名为 cluster 的计算机时,它应该连接到 localhost 端口 9418。根据您提供的 ssh 命令,localhost 端口 9418正在转发到 cluster 的端口 9418。cluster 的 ssh 服务器是否真正侦听端口 9418 而不是默认端口22?我猜测 cluster 实际上在端口 9418 上运行 Git 服务器,在这种情况下,您根本不需要修改 ssh 配置。

I'm guessing the hostname part of the Git remote URL is cluster instead of localhost. What is the output of git config remote.origin.url? If it's something like this:

git://cluster/repo.git

then change it to:

git://localhost/repo.git

How ssh port forwarding works is the ssh client opens up a port (9418 in your case) on your local machine and listens for connections. Whenever an app connects to that port, your ssh client asks the ssh server (ssh.server in your case) to open a connection to the remote side of the tunnel (cluster port 9418 in your case). All data sent to the local port is forwarded to the ssh server via the existing ssh session. The ssh server then injects the data into its connection to the destination machine. So from your perspective, you're connecting to your local machine. From the destination's perspective, you're connecting from the ssh server.

Also, your ssh config doesn't seem right. That config tells your client that whenever you want to ssh to the machine named cluster it should instead connect to localhost port 9418. According to the ssh command you gave, localhost port 9418 is being forwarded to cluster's port 9418. Is cluster's ssh server really listening on port 9418 instead of the default port 22? I'm guessing cluster is actually running a Git server on port 9418, in which case you don't need to modify your ssh config at all.

梦途 2024-11-22 20:17:39

很奇怪,因为通常应该有效:这个帮助?你有 ssh 配置位吗?

Quite odd, as that generally should work: does this help? You have the ssh config bits in place?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文