Local port forwarding examples

For more information, please see this SSH tutorial.

1. Forward agnkiaa:9000 to localhost:8080

The webpage running on agnkiaa:9000 cannot be accessed from remote clients. To visit the webpage from the local computer, we can forward the port 9000 of the host agnkiaa to the 8080 port (or any other port number you like) of localhost:

ssh -L 8080:localhost:9000 agnkiaa

Then open the browser and type localhost:8080 in the address bar.

2. Forward remote jupyter-notebook to localhost

The same applies to the jupyter-notebook running on remote servers. You can first log in to the remote server (e.g. agnkiaa) with ssh, and start jupyter-notebook with command line. A port number will be promoted in the output text, e.g. 8889. Now forward this port to your local 8890 with ssh tunneling:

ssh -L 8890:localhost:8889 agnkiaa

Then you can open the browser and type localhost:8890 in the address bar.

3. Forward remote vncserver to localhost

On the remote server, start a new vnc session with:

vncserver -geometry 1920x1080 :50

You will get an output like this:

New 'agnkiaa:50 (username)' desktop is agnkiaa:50

The message confirms that the port of the vnc session is 5950 (the vnc port starts from 5901, and :50 corresponds to 5950). Now forward this port to your local 5901 with ssh tunneling:

ssh -L 5901:localhost:5950 agnkiaa

The next step is to open vncviewer from your local computer, and connect to localhost:5901 (or simply localhost:1).