Running Jupyter Notebook Remotely

Lots of us code and process using Jupyter Notebook. While we can often run Jupyter Notebook on our laptops, for many jobs we’d like to run Jupyter Notebook on a compute node to take advantage of more: more cores, more memory, more storage…

While you can do this using a browser running on the server via X Window, a much better approach is to run Jupyter Notebook on the server and use the browser on your laptop.

 

Executive summary:

On the remote server:

jupyter notebook –no-browser –ip=0.0.0.0 –port=8447 &

On your laptop:

ssh -N -L 8447:eor-14.mit.edu:8447 dynes@eor-14

In your local browser:

http://127.0.0.1:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83

 

 

Executive summary:

On the remote server:

jupyter notebook –no-browser –ip=0.0.0.0 –port=8447 &

On your laptop:

ssh -N -L 8447:eor-14.mit.edu:8447 dynes@eor-14

In your local browser:

http://127.0.0.1:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83

 

 

Details

Doing this is a bit fiddly, but after a few times of doing this it is just cutting and pasting.

To do this, log in to the remote server.

First, Open a screen session. If you are unfamiliar with screen, it allows you to have a terminal that persists when you log off. You can reattach to the same terminal session when you log back in. You can google screen, or look here.

Second, activate the correct conda environment for what you want to do.

Third, start Jupyter Notebook on the remote machine:

   sirius:HERA_beams$ jupyter notebook –no-browser –ip=0.0.0.0 –port=8447 &

The ‘8447’ is a port number that was chosen somewhat randomly. If that port is in use Jupyter Notebook will try to find a free port. Jupyter Notebook should return with lines that look like

To access the notebook, open this file in a browser:
file:///nfs/blank/h4205/dynes/.local/share/jupyter/runtime/nbserver-3779-open.html
Or copy and paste one of these URLs:
http://eor-14.mit.edu:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83
or http://127.0.0.1:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83

Note the last line (http://127.0.0.1:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83) – you will be copying and pasting that into your local browser in a few steps.

Fourth, on your local machine (i.e. your laptop) run:

ssh -N -L 8447:eor-14.mit.edu:8447 dynes@eor-14

…replacing the 8447 with the number you  or Jupyter Notebook chose, and using your remote machine name and login in place of mine.

Finally, copy the equivalent of  the  http://127.0.0.1:8447/?token=4e52da72eee84ad854e92e9b0c49595f77cafc5304c67f83 line from the remote machine, and enter that into your web browser.

 

…and Bob’s your uncle.