Force sharing a folder, but configure in jupyterhub_config.py

Hi there,

Currently, I want to share my campus guide directory with all students and instructors. However, they only have read permissions.

The directory containing the instructions is located in the /opt/share directory on the Ubuntu WSL on the Windows server. (You can see the picture below)

image

Is there a way to share this folder with all users, within the configuration in the jupyterhub_config.py?
I cannot move this folder due to administrative issues. On the other hand, I have also used docker following some tutorials on the net, but since I use WSL1 docker doesn’t work properly.

Thanks all for the answer :heart:

So turns out, I just copy the files from a centralized folder whenever a user is being generated, using subprocess.

Demo

I have a notebook containing tutorials for students, locate at /etc/jupyter. Whenever a user creates, I just copy all files into /home/{username}.

My code before modifying:

import os, sys, pwd, subprocess

def pre_spawn_hook(spawner):
    username = spawner.user.name
    try:
        pwd.getpwnam(username)
    except KeyError:
        subprocess.check_call(['useradd', '-ms', '/bin/bash', username])

c = get_config()
c.Spawner.pre_spawn_hook = pre_spawn_hook

Using subprocess.check_call to copy files and folders to user’s home folder. Note that the user name is now the variable username:

subprocess.check_call(['cp', '-TRv', '/etc/jupyter', '/home/' + username])

However, just copy has never enough. It’s because of the misconfiguration in the folder. Just using the chmod to give the read, write, execute permission to user (Permission CHMOD 777):

subprocess.check_call(['chmod', '777', '/home/' + username + '/*'])

Final Jupyter configuration, at all:

import os, sys, pwd, subprocess

def pre_spawn_hook(spawner):
    username = spawner.user.name
    try:
        pwd.getpwnam(username)
    except KeyError:
        subprocess.check_call(['useradd', '-ms', '/bin/bash', username])
        subprocess.check_call(['cp', '-TRv', '/etc/jupyter', '/home/' + username])
        subprocess.check_call(['chmod', '777', '/home/' + username + '/*'])

c = get_config()
c.Spawner.pre_spawn_hook = pre_spawn_hook