On this page
- What should you know before exposing Jupyter?
- How do you install JupyterLab?
- How do you set a password and configure the server?
- How do you keep JupyterLab running with systemd?
- How do you connect through an SSH tunnel?
- How do you publish JupyterLab over HTTPS with Nginx?
- Which firewall rules apply?
- How do you add kernels for other environments?
- How do you update and troubleshoot JupyterLab?
- Questions
What should you know before exposing Jupyter?
A Jupyter server is a remote shell with a nice interface: anyone who logs in can run any command as the user that runs it. Treat it accordingly. Run it under an ordinary account, never as root, keep it on localhost, protect it with a strong password, and only publish it through HTTPS. With those rules it is a comfortable place for data analysis, quick experiments and teaching notebooks, with the server's CPU and memory doing the work instead of your laptop. Choose memory with your data in mind, because pandas data frames live entirely in RAM.
How do you install JupyterLab?
Create a virtual environment in your home directory and install JupyterLab plus the libraries you usually need. The Python and pip guide explains why a venv is the right place for this.
# Ubuntu and Debian
sudo apt update
sudo apt install -y python3-venv python3-dev build-essential
# Rocky Linux 9 and AlmaLinux 9
sudo dnf install -y python3.12 python3.12-devel gcc
mkdir -p ~/jupyter ~/notebooks
python3 -m venv ~/jupyter/.venv # Rocky and Alma: python3.12 -m venv
source ~/jupyter/.venv/bin/activate
pip install --upgrade pip
pip install jupyterlab pandas matplotlib
jupyter lab --versionThe version should start with 4. Packages installed into this venv are what notebooks import by default.
How do you set a password and configure the server?
Replace the random login token with a hashed password, then write a config file that pins the address, port and notebook folder.
jupyter server password
jupyter server --generate-configThe first command asks twice and stores an argon2 hash in ~/.jupyter/jupyter_server_config.json. Open ~/.jupyter/jupyter_server_config.py and add these lines near the top:
c.ServerApp.ip = "127.0.0.1"
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.root_dir = "/home/deploy/notebooks"Binding to 127.0.0.1 means nothing outside the server can reach port 8888 directly, whatever the firewall says. If you skip the password, Jupyter prints a URL with ?token=... at start; that token works too, but you would need to read it from the log after each restart.
How do you keep JupyterLab running with systemd?
A system unit that runs as your user starts JupyterLab at boot and restarts it if it stops. Create /etc/systemd/system/jupyterlab.service:
[Unit]
Description=JupyterLab for deploy
After=network.target
[Service]
User=deploy
Group=deploy
WorkingDirectory=/home/deploy/notebooks
ExecStart=/home/deploy/jupyter/.venv/bin/jupyter lab
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now jupyterlab
systemctl status jupyterlab
ss -ltnp | grep 8888
curl -sI http://127.0.0.1:8888/ | head -n 3ss should show 127.0.0.1:8888 and curl should return a redirect to the login page. Logs go to journalctl -u jupyterlab.
How do you connect through an SSH tunnel?
The tunnel is the simplest secure route: no domain, no certificate and no open port. From your own computer run:
ssh -N -L 8888:127.0.0.1:8888 deploy@198.51.100.24Leave that terminal open and browse to http://127.0.0.1:8888 on your laptop. Traffic travels inside the encrypted SSH connection, and the server port never faces the internet. If port 8888 is already taken locally, change the first number, for example -L 9999:127.0.0.1:8888. On Windows the same flag works in the built in OpenSSH client, and PuTTY has the same option under Connection, SSH, Tunnels. Combine this with key based logins from the SSH keys and hardening tutorial.
How do you publish JupyterLab over HTTPS with Nginx?
When you want to open notebooks from any browser, point lab.example.net at the server, put Nginx in front with websocket support, and tell Jupyter that it sits behind a proxy. Add to the Jupyter config:
c.ServerApp.allow_remote_access = True
c.ServerApp.trust_xheaders = TrueThen the Nginx server block (/etc/nginx/sites-available/jupyter linked into sites-enabled on Ubuntu and Debian, /etc/nginx/conf.d/jupyter.conf on Rocky and Alma):
map $http_upgrade $connection_upgrade {
default upgrade;
"" close;
}
server {
listen 80;
listen [::]:80;
server_name lab.example.net;
client_max_body_size 200m;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
proxy_buffering off;
}
}sudo nginx -t && sudo systemctl reload nginx
sudo setsebool -P httpd_can_network_connect 1 # Rocky and Alma only
sudo certbot --nginx -d lab.example.net --redirect
sudo systemctl restart jupyterlabWithout the upgrade headers the page loads but kernels never connect. Certbot installs from python3-certbot-nginx on apt systems and from EPEL on Rocky and Alma; see the Certbot guide.
Which firewall rules apply?
For tunnel access, only SSH stays open. For the HTTPS route, open 80 and 443 and nothing else; port 8888 is never opened.
# Ubuntu and Debian
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
# Rocky and Alma
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reloadAdding Fail2ban or an Nginx basic auth layer in front of a public Jupyter is a sensible extra line of defence.
How do you add kernels for other environments?
Each project can keep its own venv and still appear in the launcher. Install ipykernel into that environment and register it:
python3 -m venv ~/envs/forecast
~/envs/forecast/bin/pip install ipykernel scikit-learn
~/envs/forecast/bin/python -m ipykernel install --user --name forecast --display-name "Python (forecast)"
jupyter kernelspec listRefresh the browser and the new kernel shows up. Remove it later with jupyter kernelspec uninstall forecast. Conda users can follow the Miniconda guide and register environments the same way.
How do you update and troubleshoot JupyterLab?
Upgrade inside the venv and restart the service:
source ~/jupyter/.venv/bin/activate
pip install -U jupyterlab
sudo systemctl restart jupyterlab- Kernel keeps reconnecting: websocket headers are missing in Nginx, or a proxy timeout is too short.
- Kernel dies while loading data: memory ran out; check
journalctl -k | grep -i oomand add a swap file or a bigger plan. - Blocked request with non-local Host: set
allow_remote_accesswhen serving through a proxy. - Forgot the password: run
jupyter server passwordagain and restart.
Notebooks are plain files under ~/notebooks, so commit them to Git or include them in backups.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A2-4 | notebooks with moderate data frames | 2 vCPU, 4 GB RAM, 100 GB NVMe | $14.40/mo | $43.20 for 3 months |
| F4-16 | larger in-memory data sets | 4 vCPU, 16 GB RAM, 384 GB NVMe | $57.60/mo | $57.60 for 1 month |
| A8-16 | parallel CPU work across many cores | 8 vCPU, 16 GB RAM, 350 GB NVMe | $57.60/mo | $57.60 for 1 month |
Questions about JupyterLab on a server
Is the classic Jupyter Notebook interface still available?
Yes. pip install notebook adds Notebook 7, which is built on the same server as JupyterLab, and both can share the same password and config.
Can several people share one JupyterLab?
One JupyterLab is meant for one user. For a team, JupyterHub gives each person a separate account and server process on the same machine.
Should I use the token or a password?
Both are secure when kept private. A password survives restarts, which suits a service that runs all the time; the token suits short sessions you start by hand.
Can I run long computations and close my browser?
Yes. Kernels keep running on the server after the tab closes, but cell output produced while nobody is connected may not appear. For long jobs write results to files, or run the script in tmux.
Does JupyterLab need a GPU?
No. Data analysis, plotting and most classic machine learning run on CPU. GPU plans are not offered, so choose vCPU and memory to match your data size.
More in Python
- Install Python 3, pip and venv
- Run legacy Python 2 code
- Manage Python projects with Poetry
- Miniconda and Anaconda on a server
- Deploy Flask with Gunicorn and Nginx
- Deploy FastAPI with Uvicorn workers
- Deploy Django with Gunicorn and Nginx
- Background tasks with Celery and Redis
- Host a Python Discord bot
- Containerise a Python web app
- Host a Python Telegram bot