Connecting to a Remote Jupyter Notebook Session

Tags linux mac

Summary

Objective(s):
Run Jupyter Notebook on a remote Linux machine to be accessed via a web browser on a local MacOS device.

Pre-requisite(s):
Your Anaconda environment should already be initialized for your user account on the remote host.

Environment

  • Local: macOS, Terminal, SSH
  • Remote: Linux, Anaconda python - Jupyter Notebook

Directions

  1. Open a Terminal window on your Mac, then enter this command to connect through a forwarded port where the notebook will be told to run:
 ssh -L 8888:localhost:8888 uniqname@machinename.dept.lsa.umich.edu
  1. Enter your password to login as usual
     
  2. Now that you are logged in to the Linux machine, type the following command:
    (note 8888 is the default port for Jupyter notebook)
jupyter notebook --no-browser --port=8888
  1. This command will give you two URLs to the notebook running on the remote.
    From your terminal, copy either link to the clipboard.
    *Make sure you copy the whole token in the URL, which is the long series of letters and numbers.*
(e.g.)
http://localhost:8888/?token=somelongseriesofnumbersandletters
http://127.0.0.1:8888/?token=somelongseriesofnumbersandletters
  1. On your local Mac, open your browser of choice, paste in the address, and browse to that site.
     
  2. When you are done using the notebook, you can click the quit button at the top of the notebook site, which will close out the Jupyter Notebook that is running, or you can enter <CTRL+C> in your terminal window which will shut down the server as well.

External resources