Search code examples
linuxsshsshd

How to create a "Nested ssh tunnel"?


I connect to a linux server over 2 other server:

MyPC --(ssh)--> serverA --(ssh)--> serverB --(ssh)--> FinalServer

httpd is running on FinalServer, listen on 80 serverA/serverB only accept port 22, sshd service

Is there any way to access FinalServer on myPC like this:

myPC> curl http://127.0.0.1:80
Hi , this is FinalServer Httpd Service!!
myPC> 

Thank you a lot!!


Solution

  • In principle, you would only need to tunnel port 80 at every ssh.

    So, at every step: ssh -L80:localhost:80 <next-host>.

    However, you will not be able to tunnel port 80 (and all ports < 1024) without root privileges, so you'll have to use a different port for this.