SSH Port Forwarding VPS

June 06, 2019

When developing on a remote server you often need to connect to services running on it from your local machine (db guis / web browser / paw). One option is to open ports in the firewall and connect directly. The downside of this is that often services running in a development environment are unsecured. eg. redis.

A more secure solution is to forward local ports on you local machine to ports on the remote server. The syntax of this is always confusing are there are both local and remote ports involved. Most of the time you need ssh local port forwarding. Generally I use .ssh/config to setup the ssh connection. This allows commandline options to also be used.

eg.

ssh -L 9090:localhost:5432 skopphornet

This will allow you to connect to port 9090 on your local machine and this will in turn connect you to the postgres instance on the remote server skopphornet tunnelled securely through the ssh session.

psql -h localhost -p 9090</pre>