My setup looks like this:

 +--------+       +----------+      +-----------+
 | Laptop | <---> |  Middle  | <--> |   Server  |
 +--------+       +----------+      +-----------+

And the server is running a web server on TCP: All the machines are running SSH and I have credentials to everything.

Before there was the box in the middle, I used to have my SSH config that read:

Host server
    Hostname server.internal.tld
    User ubuntu
    IdentityFile ~/.ssh/some_key.pem
    Port 20022
    LocalForward 8081 localhost:8081
    ServerAliveInterval 60
    KeepAlive yes
    ServerAliveCountMax 1

This let me hit the page in my browser by browsing to localhost:8081.

Is there a line that I can add to my SSH config to get the same result now that there's a machine in the middle that I can proxy SSH through? Is this somehow what ProxyCommand is used for? Will the LocalForward line still work with ProxyCommand?


First Check if port 8081 of your web server is accessible from the middle server. If yes then you just have to use ip address of the server instead of localhost in LocalForward configuration. If no add following line in ssh config file

ProxyCommand ssh user_name@middle_server_ip  nc %h %p

LocalForward will work with ProxyCommand.

  • Yup, you're amazing <3 – omghai2u Jan 15 '16 at 7:11
  • Another solution is to use: ProxyCommand ssh user_name@middle_server -W %h:%p – ysdx Jan 21 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.