Port forwarding via SSH tunnels

This document explains how to use SSH tunnels to forward ports to your local computer. This can be useful for running in-browser tools like Jupyter Notebook on a server without a GUI. It is much more performant than X11.

SSH tunneling is a technology to transfer data from one computer via one port to a second computer over a second port. This is useful for running web-based tools locally on your desktop or laptop when the actual program is running on a Linux server that doesn't have a graphical user interface. Jupyter Notebook is a good example of a tool that runs on a server inside a web browser. This guide will walk through setting up Jupyter Notebook, but this can be used for any application that runs inside a web browser on a headless machine.

  1. Log onto your server via SSH normally. Once logged in, start the program that you want to forward ports to, in this case Jupyter Notebook. Note the ports used and any other information needed on the command line:

    ssh USERNAME@SERVERNAME.wisc.edu
    jupyter notebook
  1. In this example with Jupyter Notebook, you'll need two pieces of data [1 and 2 in the image]:
    1) The port your particular notebook is running on
    2) the token 
  2. In a new terminal window, I connect to the same server using an SSH tunnel:
    ssh -L LOCALPORT:localhost:REMOTEPORT USERNAME@SERVERNAME.wisc.edu 

    In this particular example, my second SSH command was:
    ssh -L 4444:localhost:8888 nairland@andersonserv.genetics.wisc.edu

    Replace the REMOTEPORT with the port from 1) in the image, in this case 8888. LOCALPORT in the command, for which I picked 4444, will be the port on your computer that the data from port 8888 on the server will be forwarded to. 
  3. In your web browser, put 'localhost:LOCALPORT' in your URLbar - in this case, localhost:4444
  4. For Juypter Notebook, you'll then be asked for your token [2 from the first image] - copy and paste that in to connect to the notebook.


Keywords:
linux, genetics, ssh, x11, port forwarding, tunnel, tunneling, jupyter notebook 
Doc ID:
154458
Owned by:
Nils I. in CALS Information Technology
Created:
2025-08-27
Updated:
2025-08-27
Sites:
College of Agricultural & Life Sciences