How to open multiple port forwards with one line using OpenSSH

The solution to this is so simple that I’m probably going to forget it in a couple of days 😉 Going to put it here for me to find next time I forget

Here it is:

ssh -N -L 12345:localhost:12345 -L 23456:localhost:23456 -L 34567:localhost:34567 user@server

This will setup 3 port forwards on localhost from server. Need more ports? just add another -L section and you are set

Tested on OpenSSH 7.8p1 and LibreSSL 2.6.2

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.