SSH tunnel to allow ssh traffic: connection always refused

gitsshssh-tunnel

I have access to two servers at work. Server A hosts git repositories and is externally visible. I would like to be able to clone a repository into Server B which is hosted on Server A.

Currently, I can't ssh from Server B to Server A. I am assuming the firewall is blocking that.

So I am trying to create an ssh tunnel following writeups I've come across, but so far to no avail.

From Server A's shell:

$ ssh -L 1234:localhost:22 user@server_b

This successfully logs me in to Server B. From there I can't seem to do anything using ssh:

$ ssh user@localhost
$ user@localhost's password: <entered correctly>
$ Permission denied, please try again.

$ ssh user@localhost -p 1234
$ ssh: connect to host localhost port 1234: Connection refused

Trying to clone

$ git clone ssh://user@localhost:1234/path/to/repo.git/
$ ssh: connect to host localhost port 1234: Connection refused
$ fatal: The remote end hung up unexpectedly

Is my initial tunneling command incorrect? Or might I need to get the network admin to open something up on the firewall?

Best Answer

You need to create a reverse tunnel with -R instead of -L.

On your local machine, use

ssh -R 1234:server_a:22 user@server_b

You'll get a shell on server_b. If you do

ssh -p 1234 user@localhost

on this shell, this will connect you to port 22 of server_a, tunneled through your local machine.

After that, your git clone command should work.