For a recent project, I found myself doing web app development on another machine that was accessible only over SSH. Since the webserver would be hosted on the remote machine, I needed to allow secure port forwarding.

Trivially, if I am running web server on the remote machine over port 8000, then I can easily set the SSH’s port forwarding feature so that I can access it at localhost:8000 on my local machine using the following:

$ ssh <username> -L 8000:localhost:8000

This solves the problem but another thing would be if you have two different servers running on the remote machine… SSH thankfully provides the possibility to forward as many ports as you need without the need for any complicated configuration. ALl you have to do is pass the flag -L for each instance of port forwarding that you desire. For example, if I have servers running on port 8000, 9000 and 3000 then I can pass the command below

$ ssh <username> -L 8000:localhost:8000 -L 9000:localhost:9000 -L 3000:localhost:3000

which will allow me to access the servers on my local machine at the address, localhost:8000, localhost:9000 and localhost:3000.