Jupyterhub configurations - https (with a self signed certificate) and starting with a shared directory for multiple users


Generate the default configuration file. 
$jupyterhub --generate-config

This will generate the default configuration that will be used by Jupyterhub, in the directory where the command is run. We are going to do changes. But, running this proves the fact that Jupyterhub installation has been successful in your box. 

Rename the config file. Call this as def_config.py

Move this config file to the site-packages directory where jupyterhub is installed. 

If you do not know the site-packages directory where jupyterhub is installed, do execute the command,
$sudo find / -iname jupytherhub

You will find a lot of results.. In those results check for the site-packages directory.. it will be something like
……/python3.x/site-packages/jupyterhub/

Make a copy of the def_config.py and call it as ssl_config.py in the same folder
……/python3.x/site-packages/jupyterhub/

Run the following command to create a self signed certificate
$ openssl req        -newkey rsa:2048 -nodes -keyout domain.key        -x509 -days 365 -out domain.crt
You do not need to input  any values… keep on giving “enter command”

Finally, this will generate domain.key and domain.crt – two files where the command is run

Run the following command to generate the cookie secret file.
$openssl rand -hex 32 > ./jupyterhub_cookie_secret

This will create jupyterhub_cookie_secret in the directory where the command is run. Please note the location of all the three files - domain.crt, domain.key and the cookie secret file. They need to be specified in the config file.

Let us assume that all these files are in the directory “/home/centos/”. 

Create a folder that is to be used as the common landing location for users. 
Let us call this /home/jupyterHubShare. Give a 777 permission for this directory so that any logged in user can get to view the list of files in this directory.

Make the following changes in the as ssl_config.py file. You need to uncomment the lines having the properties shown below (properties are at the left hand side of each line) and the values for those uncommented properties need to be as given below.

c.Application.log_level = 'DEBUG'
c.JupyterHub.cookie_secret = b'/home/centos/jupyterhub_cookie_secret'
c.JupyterHub.debug_db = True
c.JupyterHub.extra_log_file = '/home/centos/jupyterhub_ssl.log'
c.JupyterHub.port = 443
c.JupyterHub.ssl_cert = '/home/centos/domain.crt'
c.JupyterHub.ssl_key = '/home/centos/domain.key'
c.Spawner.debug = True
c.Spawner.notebook_dir = '/home/jupyterHubShare/'
c.PAMAuthenticator.open_sessions = False

Execute the following command to start Jupyterhub
$ sudo jupyterhub -f  /usr/lib/python3.4/site-packages/jupyterhub/jupyterhub_ssl_config.py

In your browser, do type
https://ipaddress or hostname where jupyterhub is run:443
or 
https://ipaddress or hostname where jupyterhub is run:443/hub/login

You will see a warning that the site is not trusted - since we used a self-signed certificate. Instruct the browser to ignore the same and continue to the site. You will get the login page.

You can login with your credentials - either a local linux user or an AD user (if you had logged into the box using your AD credentials at least once before logging through Jupyterhub - say through ssh). In the case of AD user, I had not done any specific changes to config, as my box had already joined AD.

Comments

Popular posts from this blog

Jupyterhub Offline install (without internet!)