how to ssh to the machine behind the firewall? [duplicate]

Possible Duplicate:
SSH to a computer that will then SSH to another computer

I have 3 Linux machines A, B and C.

I can ssh from A to B; B to C but not from A to C directly because C is behind a firewall.

Is there a way that I can be able to ssh from A to C directly? I heard about tunneling but I don't know how. I have only root permission in A, but not B and C.


You can set up an SSH tunnel from B to C like this:

ssh -L 50022:C:22 user@B

Where B and C are the respective addresses of those servers. Then you can connect directly to C by using the tunneled port:

ssh -p 50022 user@localhost

In this case, user is the user you want to connect to C as. The connection will be tunneled over the established ssh connection. B will connect to C and proxy the traffic.

(Note that the choice of port 50022 is arbitrary; you can pick anything that's not in use on your local machine.)


You can create a tunnel from A to C, through B.

From A:

ssh -fgN -L 2222:C:22 B

The above command would run ssh in the background. It would connect you to B, start a tunnel listening on A, localhost, on port 2222, connecting to C port 22.

Now on A, you can ssh to C by using port 2222:

ssh -p 2222 localhost