How do I set up two hop ssh tunneling

I have a gateway system which is connected by vpn to a remote server.  I can ssh (or vnc) to the gateway from my host system and then ssh (or vnc) to the remote.  I would like to do this in one step, by creating a tunnel from the host system to the remote via the gateway.

I can create a local tunnel on the gateway system using ssh:
  [host] $ ssh gateway
  eager@gateway's password: ********
  [gateway] $ ssh -N -L 1234:remote:22 -f remote
  eager@remote's password: *******
  [gateway] $ ssh localhost -p 1234
  eager@localhost's password: *******   [password for remote]
  [remote] $

If I try to connect to the gateway port 1234 from the host system, it fails:
  [host] $ ssh gateway -p 1234
  ssh: connect to host gateway port 1234: Connection refused

Is there a way to set up a two hop tunnel:
  host:1234 ==> gateway:1234 ==> remote:22

Can this be done with SSH?  Or VPN?  
Who is Participating?
You are doing it the wrong way.

The correct tunnel setting would be:
[host] $ ssh -N -f -L 1234:remote:22 gateway
eager@gateway's password: ******
[host] $ ssh -p 1234 localhost
eager@remote's password:

Open in new window

eagerAuthor Commented:
Thanks.  That was my confusion.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.