Notes on installing jupyter hub with jupyter notebook on RPI4 ubuntu 20.04 lts

As of 8-11-21 NativeAuthenticator works. The instructions below work if FirstAuthenticator is replaced with NativeAuthenticator.Will update.

It is important to have at least one administrative user with sudo privileges so they can do sudo -E pip install ... from a terminal within the hub to install things hub wide.

Although aimed at a small system on a Pi4 for multiple users, this will work on any computer with Ubuntu 20.04 lts.

This sets up a hub where new local user accounts are created on first login using a combination of FirstUseAuthenticator and LocalAuthenticator. The idea is to use this on a shared computer used for data collection through Jupyter. Users can only log into these accounts through the jupyterhub.This way users end up with their own account so that they do not damage each other's data.

Slight modifications on the instructions for a jupyter hub found here and an issue for NativeAuthenticator. Would prefer to use NativeAuthenticator rather than FirstUseAuthenticator but templates seem to be messed up so the sign-up page does not display.

sudo python3 -m venv /opt/<hub name>/
sudo /opt/<hub name>/bin/python3 -m pip install wheel
sudo /opt/<hub name>/bin/python3 -m pip install jupyterhub
sudo /opt/<hub name>/bin/python3 -m pip install jupyterhub-firstuseauthenticator
sudo /opt/<hub name>/bin/python3 -m pip install jupyter
sudo apt install nodejs npm
sudo npm install -g configurable-http-proxy
sudo mkdir -p /opt/<hub name>/etc/jupyterhub/
cd /opt/jupyterhub/etc/jupyterhub/
sudo /opt/<hub name>/bin/jupyterhub --generate-config

In the generated config file replace the standard authenticator with the FirstUseAuthenticator and LocalAuthenticator to create users if necessary:

c.Authenticator.admin_users = {'<admin account name>'}
c.Authenticator.open_signup = True
c.LocalAuthenticator.create_system_users = True
from jupyterhub.auth import LocalAuthenticator
from firstuseauthenticator import FirstUseAuthenticator
class LocalNativeAuthenticator(LocalAuthenticator, LocalAuthenticator):
  pass
c.JupyterHub.authenticator_class = LocalNativeAuthenticator

Make sure nobody can create an account with the name root or login as root. Set: c.Authenticator.blocked_users = {'root'}

Bind to localhost only: c.JupyterHub.bind_url = 'http://localhost:8000'

Since this is a Pi4 keep the spawn limit low: c.JupyterHub.concurrent_spawn_limit = 20

Systemd services:

sudo mkdir -p /opt/jupyterhub/etc/systemd

Create file in this directory called, <hub name>.service, with the following content:

[Unit]
Description=<hub name>
After=syslog.target network.target

[Service]
User=root
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/<hub name>/bin"
ExecStart=/opt/<hub name>/bin/jupyterhub -f /opt/<hub name>/etc/jupyterhub/jupyterhub_config.py

[Install]
WantedBy=multi-user.target

Set up to start on reboot and launch:

sudo ln -s /opt/jupyterhub/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
sudo systemctl daemon-reload
sudo systemctl enable <hub name>.service
sudo systemctl start <hub name>.service

To check the status: sudo systemctl status <hub name>.service

Access the hub from a local browser pointed at http://localhost:8000.