Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
A million times thank you. For future reference to anyone who stumbles across this, I actually wrote 'localhost' in place of 'server_a' in your response. – circuitBurn Apr 17 '13 at 17:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.