How to set up a public server for JupyterLab?
Many of us are provided access to GPU clusters or storage space on a server (Linux-based) for various purposes, be it for research or just as such. Such accounts are generally used by ssh
ing via the terminal, which restricts us to terminal-based editors for coding, apart from making the task of project maintenance tedious.
I wasn’t very comfortable using vim for large projects, and was in search for a solution when I came across JupyterLab. Here, I provide a step-by-step tutorial to set up a public server for JupterLab, so that you can have a password-authenticated, browser-based IDE. No more cumbersome ssh
ing!
Setting up a proxy for internet access
(Ironically?) ssh
into the server.
In case your account does not have internet access, you will first need to set up a proxy. For this, you will need to know the details about the proxy server provided by your institute. I will consider netmon.iitb.ac.in
for the remaining steps.
Add these lines to ~/.profile
file
Execute source ~/.profile
to reflect these changes in the current session. Other possible alternatives are using a terminal based browser to login to internet.iitb.ac.in
, but the one mentioned above is the least tiring!
Setting up JupyterLab and packages locally
This installs jupyter and jupyterlab in ~/.local/bin
directory; you don’t need root access for this. You can locally install other packages required for the project to ~/packages
directory by using
Also add packages/
to the PYTHONPATH
variable so that Python can look for packages in this directory. This can be done by adding this line to ~/.profile
Remember to use --user
instead of --target <DIR>
when the package to be installed contains executables. This is because executables are searched for in the PATH
variable, unlike library packages. Also, execute source ~/.profile
in order to reflect these changes in the current session.
Configuration
Generate a configuration file for Jupyter Notebook in ~/.jupyter
Generate a password for authentication
The password is stored as a hashed value in json
format in ~/.jupyter/jupyter_notebook_config.json
.
Edit the ~/.jupyter/jupyter_notebook_config.py
file by changing these lines
After making these changes, enable the serverextension
for jupyterlab
by executing
Starting the server
For hosting the server, you will need screen
or an equivalent utility that allows commands to be run even when the connection to the server is interrupted.
- Start a new screen using
screen -S jupyterlab
. - Simply execute
jupyter lab
to start the server. - Press
Ctrl+A
and thenCtrl+D
to detach from the screen. - Close the connection to the server.
Using JupyterLab
Open a browser and visit IP:PORT
(these are the values you had entered in the jupyter_notebook_config.py
file). You will be redirected to a login page, where you need to enter the password. After authentication, you will be able to use a browser-based IDE, complete with terminal support, directory listing and lots more!
Cheers!