开发者

git push using port forwarding (SSH tunnel)

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 username@ssh.server

but I am still not able to run开发者_如何学Python "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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜