You can use JupyterHub's hook
function to automatically create a directory for each user when you log in.
Define it as a function in the configuration file (jupyterhub_config.py
).
There are the following types of hooks.
c.JupyterHub.user_redirect_hook
c.Spawner.auth_state_hook
c.Spawner.post_stop_hook
c.Spawner.pre_spawn_hook
c.Authenticator.post_auth_hook
Sample scripts are available in the official repositories.
jupyterhub/examples/bootstrap-script at master ยท jupyterhub/jupyterhub
For example, the hook action that automatically creates a user folder is as follows.
# in jupyterhub_config.py
import os
def create_dir_hook(spawner):
username = spawner.user.name # get the username
volume_path = os.path.join('/volumes/jupyterhub', username)
if not os.path.exists(volume_path):
# create a directory with umask 0755
# hub and container user must have the same UID to be writeable
# still readable by other users on the system
os.mkdir(volume_path, 0o755)
# now do whatever you think your user needs
# ...
pass
# attach the hook function to the spawner
c.Spawner.pre_spawn_hook = create_dir_hook