Let’s say you are developing an application in your computer, and you want others to see it. For that, you first host the app locally making it accessible from localhost. Then, you wonder what you can do to share it with people outside of your network. Remote port forwarding SSH can solve this problem.
In Linux terminal or PS/CMD on Windows, from the computer where you have the app or website hosted, you’ll using a command like the following:
ssh -R 8888:localhost:8001 user@remote.host
Where:
- SSH tells the computer that you want to create a secure encrypted connection between two host.
- -R switch specifies the connection on the remote server is going to be forwarded to the local side.
- 8888 is the port where you want the server to listen.
- localhost:8001 is the IP and port where you have you app or website hosted (your local computer)
- user@remote.host is the user and IP of the server you’re connecting to.
Change the values to the ones you need. This is going create a tunnel between port 8888 in your server to localhost:8001 in your local computer. In your server, the option GatewayPorts should be set to “Yes”, otherwise the connection is not going to work.
After you run the command, you’ll asked to introduce the password for the user that is requesting the connection. Once the ssh tunel is established, you’ll be able to use remote.host:8888 from any computer connected to the internet. As explained your server will be redirecting traffic from remote.host:8888 to your local ip and port.