PowerShell Collaboration Unleashed: Setting Up The Littlest JupyterHub

This post is an accompanying post for the JupyterHub Install with PowerShell Notebooks video that is part of the PowerShell Collaboration Unleashed series.

Connect to remote server

ssh <username>@<server-ip/name>

Install The Littlest JupyterHub

You can change hubadmin to whatever you want your admin account to be named.

Remove the slash (\) at the front of this command. For some reason WordPress would not let me save a curl command.

\curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - --admin hubadmin

Install .NET SDK and Notebooks

Get the OS verion

cat /etc/os-release
export VERSION_ID=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f 2)
echo $VERSION_ID

Download Microsoft’s package repository for Ubuntu

Where the URL contains $VERSION_ID, which is dynamically replaced with the version of Ubuntu you are using. This file is Microsoft’s repository configuration for installing Microsoft products on Ubuntu.

Remove the slash (\) at the front of this command. For some reason WordPress would not let me save a curl command.

\curl -O "https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb"

Install the repository package

sudo dpkg -i packages-microsoft-prod.deb

Delete the package file

It is no longer needed after installing the repository

rm packages-microsoft-prod.deb

Refresh the list of available packages

This refreshes from all configured sources, including the Microsoft repository that was just installed.

sudo apt update

Install the .NET SDK

In this case we are installing the dotnet-sdk-8.0 package. This can be updated to newer versions as they are released in the future.

sudo apt install -y dotnet-sdk-8.0

Install dotnet interactive SSH terminal to the tljh directory

sudo dotnet tool install Microsoft.dotnet-interactive --tool-path /opt/tljh/user/bin

Connect to JupyterHub

  1. Open web browser and navigate to – http://<server-ip/name>
  2. Login as hubadmin (or whatever name you specified during the install) and type any password to set it

Install .NET Notebooks

Open a Terminal window in JupyterHub and enter the command below.

dotnet interactive jupyter install

Create Notebook to install .NET Notebooks

Create a new Python notebook named ‘Install PowerShell Kernels.ipynb’. This will be used by other users to install the .NET notebooks into their environment. Enter the script below into the notebook and save it.

## Importing subprocess module
import subprocess
## execute shell command to install dotnet interactive objects
subprocess.Popen('dotnet interactive jupyter install', shell=True)

Create ‘Get-Module.ipynb’

Get-Module -ListAvailable

Create Shared Directories

Create three shared Directories.

  • setup – will be read-only
  • shared – will allow users to save and share notebooks, but others cannot edit their notebooks
  • collab – all user will have full read/write access to all notebooks in this folder

Except where noted all commands are entered in a terminal in JupyterHub

Create the read-only shared folder

sudo mkdir -p /srv/data/setup
sudo ln -s /srv/data/setup /etc/skel/setup

Copy the Install PowerShell Kernels notebook into it

sudo cp 'Install PowerShell Kernels.ipynb' /srv/data/setup

Create the shared folder

sudo mkdir -p /srv/data/shared
sudo ln -s /srv/data/shared /etc/skel/shared
sudo chown root:jupyterhub-users /srv/data/shared
sudo chmod 777 /srv/data/shared
sudo chmod g+s /srv/data/shared

Copy the Get-Modules notebook into it

cp 'Get-Module.ipynb' /srv/data/shared

Create a collaboration folder

Back in the SSH session install the Access Control Libraries.

sudo apt install -y acl

Back in JupyterHub

sudo mkdir -p /srv/data/collab
sudo ln -s /srv/data/collab /etc/skel/collab
sudo chown root:jupyterhub-users /srv/data/collab
sudo chmod 777 /srv/data/collab
sudo chmod g+s /srv/data/collab
sudo setfacl -d -m group:jupyterhub-users:rwx /srv/data/collab

Known Issues

Depends: libicu but it is not installable

THe error above can appear during the .NET SDK installation. It can be caused when the dependencies cannot be reconciled properly. First check that you have listed the correct version for your Ubuntu server into the URL for downloading packages-microsoft-prod.deb. If you confirm you have the correct version and still receive this error, you can get around it by deleting the microsoft-prod.list file using the commands below. Then running the update and install again.

WARNING: This could have unintended consequences and should only be used as a last resort.

sudo rm /etc/apt/sources.list.d/microsoft-prod.list
sudo apt update 
sudo apt install -y dotnet-sdk-8.0