JupyterHub
Jump to navigation
Jump to search
Setup JupyterHub
- create new user and group jupyterhub and put user in group shadow
- allow sudo for members of group. Create /etc/sudoers.d/jupyterhub
Cmnd_Alias JUPYTER_CMD = /home/jupyterhub/miniconda3/bin/sudospawner jupyterhub ALL=(%jupyterhub) NOPASSWD:JUPYTER_CMD
- install conda for that user
script=Miniconda3-latest-Linux-x86_64.sh wget "https://repo.anaconda.com/miniconda/$script" chmod +x "$script" "./$script" -b ~/miniconda3/bin/conda init bash . ~/.bashrc conda update conda
- install packages (Minimum: jupyter hub, sudospawner and lab. Recommended: language server and other useful stuff...)
conda install -c conda-forge jupyterhub jupyterlab jupyterlab-lsp python-lsp-server sudospawner opencv pandas matplotlib
- configure jupyterhub
jupyterhub --generate-config -f jupyterhub_config.py add line "c.JupyterHub.bind_url = 'http://:7000'" to config file
- start the hub
jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
- login at http://localhost:7000
JupyterHub with SSL
super easy if you already have a cert and key (e.g. from letsencrypt): add these two lines to /home/jupyterhub/jupyterhub_config.py
c.JupyterHub.ssl_cert = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/fullchain.pem' c.JupyterHub.ssl_key = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/privkey.pem'
JupyterHub as a Service
- create script to init conda environment and then start jupyterhub
#!/bin/bash . ~/.bashrc exec jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
- create systemd script /etc/systemd/system/jupyterhub.service
Description=Jupyterhub [Service] User=jupyterhub ExecStart=/home/jupyterhub/jupyterhub.sh WorkingDirectory=/home/jupyterhub [Install] WantedBy=multi-user.target
- Install own kernel with conda environment
- start terminal and create conda environment as usual (or list existing envs to choose from)
- register new kernel
python -m ipykernel install --user --name my-new-env --display-name "Python (my-new-env)"
- reload hub page and start Launcher (+) to see the new kernel