Multiple SSH Tunnels

This week I needed to set up connections to 4 different Windows servers, each hosted at the same hosting provider. They will be running different components of one application, so I’ll probably be accessing all of them at once. Simple enough, except that in order to connect to the servers I need to access the hardware VPN that is located in our office on the other side of the country!

I knew that I needed to set up a SSH tunnel from my laptop (a MacBook) to the servers, but I certainly did not want to open 4 different shells each time I wanted to connect to all the servers. Each of the 4 tunnels needs to pass through the same server located within the firewall at our office.

Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command. The command to do this is: ssh -L :: -L :: @ So, say that I wanted to set up local ports 10001 and 10002 to connect to a couple of servers at securedomain.com and tunnel through trusteddomain.com.

he command would then look like: ssh -L 10001:one.securedomain.com:3389 -L 10002:two.securedomain.com:3389 steve@tunnel.trusteddomain.com Hope this helps someone else out!

  • http://marcuswilson.tumblr.com TheWilson

    Hi Steven. This did help out someone :)

    Also this is the first result for the search :
    ssh forward multiple ports

  • dergachev

    Excellent, thank you Steven! And on top of everything, I’m using this with Vagrant and Drupal. :)

  • Wycito

    Awesome, so used to use GSTM that neglected to use the terminal for such things, so I find myself is someone else’s linux box and you came to the rescue :) , thank you