Most good sysadmins already know how to forward a local port to a remote machine and vice versa. However, sometimes it is useful to open a port on the remote machine to the world and have that traffic forwarded through SSH to your local machine.
A practical reason for this is if your web development server is sitting in the wild and you are in your comfy office behind a firewall. Perhaps you just want a wild server to forward a port into a box on your local network without anybody being the wiser. Well here’s how you do it.
- On the Remote Machine make sure this is in sshd_config, GatewayPorts yes
- Restart ssh
- On your local machine create the tunnel with:
ssh -R 8080:localhost:8080 user@remotehost
Now you should be able to access remotehost:8080 and SSH will tunnel the traffic to your local machine.
PS: this could be a potential security problem if you’re not smart.
