Remote access to Jupyter lab

This is going to be a checklist ie. do this, and you'll be fine.

Install jupyter-lab

preferably in a virtual environment.

Then run

$ jupyter server --generate-config
$ jupyter server password
Enter password:....
Verify password:...

This will create

  • $HOME/.jupyter/jupyter_server_config.py
  • $HOME/.jupyter/jupyter_server_config.json

Create a self signed certificate

openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout mycert.pem -out mycert.pem

openssl will ask you a bunch of questions. The only important one is the FQDN. If you don't have one you can use your zero conf name (ie. yourmachinename.local) or your IP address (i think).

Store the resulting mycert.pem file wherever you want, really.

Now you've got two options.

  1. Create a shell script
  2. Use the generated jupyter_server_config.py

The shell variant

Create a shell script (remember to make it executable).

#! /bin/bash

jupyter lab --no-browser --ip "*" \
  --notebook-dir /path/to/notebook/dir \
  --certfile=/path/to/mycert.pem \
  --port=9999

For good measure you could add inn activation of your virtual env.

The config variant

Edit $HOME/.jupyter/jupyter_server_config.py

There are a lot going on in that file. However, you'll will only have to add 5 lines.

In around a comment reading ## The full path to an SSL/TLS certificate file. add these lines:

c.ServerApp.certfile = '/absolute/path/to/mycert.pem'
c.ServerApp.keyfile =  '/absolute/path/to/mycert.pem'
c.ServerApp.password = The hashed password found in jupyter_server_config.json
c.ServerApp.ip = "*"
c.ServerApp.open_browser = False
c.ServerApp.port = 9999

Personally I prefer the script variant, mainly because I have no clue what's going on in the config file and if it should matter to me.

In either case, this will give you a jupyter instance to which you can connect remotely. The instance is password protected, and you will have to accept the SSL certificate (since it's self signed) in your browser before proceeding.

So.. there's that.