Skip to content

Instantly share code, notes, and snippets.

@mehdirezaie
Last active August 10, 2021 06:56
Show Gist options
  • Save mehdirezaie/25f118b10e267e30648a0b88d35bdd4a to your computer and use it in GitHub Desktop.
Save mehdirezaie/25f118b10e267e30648a0b88d35bdd4a to your computer and use it in GitHub Desktop.
How to connect to a Jupyter Notebook remotely

Jupyer Notebook

Jupyter Notebook has become an essential element of exploratory data analysis and data visualization pipelines. In this note, I will give the instructions on how to start a jupyter kernel remotely and connect to it.

  1. On the server, install Jupyter Notebook
  2. On the server, initialize a kernel using an arbitrary port number (e.g., 1234) jupyter notebook --no-browser --ip=localhost --port=1234. Copy the token number from the output log. Note you can use any port number.
  3. On the local, execute ssh -N -f -L localhost:8888:localhost:1234 user@server where you need to replace user with your username and server with your server. This command will initiate a channel from server's localhost:1234 to local's localhost:8888. Again, you can use any port number. You just need to be consistent.
  4. Go to localhost:8888 in your local browser, you may need to enter the token number which you have copied in step 2.

In case you forget the Token number, execute the following command on the server: jupyter notebook list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment