1

I'm trying to ssh through multiple hosts which works with no problems like so:

ssh -t -t user1@host1 ssh -t -t -p 222 user2@host2

Now I would like to use local host for access to a third host and I do it like so:

ssh -L 2222:host3:22 -t -t user1@host1 ssh -p 222 user2@host2

Problem:

When I do ssh -p 2222 user3@localhost nothing happens (like that the connection is timing out). Whilst ssh -t -t user1@host1 ssh -t -t -p 222 user2@host2 ssh user3@host3 works absolutely fine.

Arman
  • 165
  • 1
  • 1
  • 5

1 Answers1

1

The -L 2222:host3:22 is forwarding a local port 2222 to host3:22 via host1. I assume the host1 does not have a connectivity to host3. If it had, you would not be connecting via host2.

You need to forward a port from host1 to host2 and then forward the local port to the forwarded port on host1.

This should do (I cannot test atm):

ssh -L 2222:host2:2223 -t -t user1@host1 ssh -L 2223:host3:22 -p 222 user2@host2

localhost:2222 => host2:2223 => host3:22

Martin Prikryl
  • 7,327
  • 2
  • 36
  • 71