Skip to content

Jupyter

Setup SSH access via proxy

The instructions below will need SSH access from your client to the server. Please follow the instructions here:

to simplify access to the server before you follow the instructions below.

Notebook server

It is possible to run the Python kernel of a Jupyter notebook on a server and remotely access this notebook on your desktop or laptop (the client) via a webbrowser.

Setup Python Virtual Environment

The Python virtual environment with jupyterlab package will be used in this instruction. Follow these instructions to setup the virtual environment:

After activating the virtual environment add the package jupyterlab to the requirements.txt file and install it with:

pip install -r requirements.txt --upgrade

Setup Jupyter server

First activate the virtual environment and create the Jupyter configuration file:

jupyter-lab --generate-config

Create a password to secure access to your Jupyter Lab which will be requested when opening the website:

jupyter-lab password

To encrypt your connection over the internet setup an SSL certificate which will be used when starting up the Jupyter server:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout jupyter_server.key -out jupyter_server.pem

Start Jupyter server

You are now ready to start the Jupyter server with the SSL certificate:

jupyter-lab --certfile=jupyter_server.pem --keyfile jupyter_server.key

The server will be started and show you the log information on the terminal. The webinterface (the actual Jupyter Lab) is accessed via port 8888 or higher depending if the port is free. Remember this port number for the instructions below! If you are ready using the notebook server you can quit the server in the terminal with Ctrl+C.

Open Jupyter Lab on client

You can now access your Jupyter Lab via your desktop or laptop (the client) via a SSH-tunnel.

SSH-tunnel

The ImPhys servers are behind a firewall which will not allow you to directly access the server via port 8888 (or higher). This can be solved by opening up a SSH-tunnel through the bastion host between the server and your client which will use the ssh-connection over port 22 to pass through the otherwise blocked traffic to port 8888 (see the diagram below):

ssh tunnel

The data transport from the server on port 8888 is tunneled to the client on port 18888. This enables the user to access the remote port 8888 via the local port 18888. You can then access the notebook on the browser on your desktop or laptop via the URL https://localhost:18888.

In Linux or in Windows with Windows Subsystem for Linux (WSL) this tunnel is created on the client as follows using the port number shown in the log of the Jupyter Server (in this example 8888):

ssh -L 18888:localhost:8888 saturn # or jupiter

Info

The name saturn or jupiter is setup in the SSH configuration file (see Configuring SSH with a Configuration File)

Note

The tunnel will remain open as long as your ssh-connection is up.

PuTTY in Windows

In Windows you can also create a tunnel with PuTTY. For more information check:

On your client now open a browser and use this URL:

Warning

You must use https otherwise the SSL connection will not be made.

You will get a warning that the SSL certificate is not properly signed. Ignore this warning and accept the connection nonetheless. You will also need to fill in the password you’ve set earlier. After that the Jupyter Lab website will be shown.

Check connection

You can easily check if your Jupyter client is actually using the Jupyter server with the following code:

import socket
print(socket.gethostname())

This should give you the hostname of the Jupyter server.