3

I have three computers, A, B, C. A is the computer I'm working on, C is the remote computer I'd like to access. However C can only be accessed through B. Only B has a ssh server, and only A has a ssh client.

What command am I to use (preferably on A) so that I can connect to C (port 80) through B ? For example B should forward all incoming port 12345 to C:80.

I know this is a common question and I found a ton of commands on google but none seemed to work.

Once it is set up, I'm supposed to just use localhost:5678 on A, which connects to B:1234, and then forwards to C:80.

Thanks.

1 Answer 1

2

It might be that the sshd daemon is set to disallow port-forwarding to other machines or to disallow port-forwarding at all. Anyway, the correct command to issue at A to access C at port 80 as follows:

ssh -L localhost:5678:<ip-or-name-of-C>:80 <ip-or-name-of-B>

After the ssh session is established you connect to localhost:5678 to get connected to C:80. If you wish any inbound connection to the host A:5678 be forwarded to C:80, then remove localhost: from the command above.

If the port-forwarding to other hosts is disabled at B, then you could try the chaining, described here

2
  • This is it, thank you. However, I do get to the prompt of B. If I want to avoid that, I have to add -nN, right ?
    – Car981
    Feb 25, 2013 at 16:06
  • the -N is enough to not start a remote shell. if you wish to put ssh into background then, yes, add the -n switch
    – Serge
    Feb 25, 2013 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .