Port forwarding for Windows using PuTTY
The popular free PuTTY ssh client for Windows has almost as many options as the original OpenSSH client for *n*x systems from the OpenBSD Foundation. Among some of its lesser-known capabilities are port forwarding and port translation facilities and this article shows how to use these to open a Jupyter Notebook on a remote Linux system; for the screenshots, the compute server called cfm-ic1.ma.ic.ac.uk which has external SSH access on the "obfuscated" ssh port 10022 is used but any system and any ssh port (including the default port 22) can be substituted for these.
If you don't already have PuTTY installed on your Windows system, you can download and install it yourself from:
Launch PuTTY and set up the 'Basic Options for your PuTTY session' as shown below, entering the hostname of the system you want to connect to, the port it uses for ssh (by default this is 22 but is sometimes changed for security reasons) and selecting SSH as the connection type:
- now click on 'SSH' in the left-hand pane to expand the SSH options as shown below:
- next click on 'Tunnels' in the left-hand pane and a new window called 'Options controlling SSH port forwarding' appears:
- now check the box 'Local ports accept connections from other hosts' and in the section headed 'Add new forwarded port', add the following settings:
Source port: 8888
- click on the 'Add' button and the screen should now look like the one shown below:
- now you can click on the 'Open' button, log into cfm-ic1 in the usual way and type:
jupyter notebook --no-browser --port=8889
- to start jupyter notebook on port 8889 (as well as the usual port 8888) as shown below:
- On some systems, this simple jupyter notebook command may not work and you will get an error message such as:
OSError: [Errno 99] Cannot assign requested address
- in that case try adding the
option to your command line so that it becomes
jupyter notebook --no-browser --ip=127.0.0.1 --port=8889
as shown in the screenshot below (this screenshot is actually from a different computer which is exhibiting this issue):
- Note that on this particular computer, it is requesting an authentication token be entered as part of the URL and invites the user to copy and paste one of two URLs: if you do this, do remember to change the port 8889 shown on the remote system's screen to port 8888 since you will be using port translation to access this URL. (You will be accessing localhost:8888 on your Windows system which PuTTY will translate over the ssh link to arrive at 127.0.0.1:8889 on the remote system).
- Finally, the screenshot below shows the result of starting a browser on the Windows system (Firefox in my case) to access the URL:
- What is happening is SSH has created a tunnel in parallel to the existing connection on port 10022 which connects port 8889 on cfm-ic1 to port 8888 on the Windows system; you can still use the port 10022 link at the same time as the new port 8888 <--> 8889 link. Also, as you can see in some of the earlier screenshots, I have previously saved my session in PuTTY as 'cfm-ic1_tunnel' which avoids typing in all these settings every time I connect. This is optional, of course.
Research Computing Manager,
Department of Mathematics
last updated: 17.2.2021