We have an idea for a data science application where jupyterhub is central.
The core idea is for users to create projects on our application and work in teams, each project will have a shared folder in jupyterhub. Each project folder should only be accessible/visible to its team members, and each team member can edit files in that folder.
I’m new to JupyterHub but I’ve figured out how to create folders, create ‘groups’, and add users to the group through TLJH API, however, I’m struggling to envisage how to create group-specific folders which are writable to all members.
If anyone has any ideas on how to set this up, I’d love to hear it.
If you’re using TLJH your Jupyter users are also users on the operating system. You can therefore use standard Linux users, groups and permissions to create directories that are readable/writeable by one group.
When it rains it pours, I’ve almost finished a script that creates user accounts and groups before allocating relevant permissions. The shell scripts you linked are still useful.
Feel free to point me towards any other useful repositories.
Let me know if you’d prefer I make a new post for this question.
I took the advice given by @manics - using standard linux commands to create groups and permissions. I made a shell script to handle this.
I then added the ability to create users to this shell script.
prefix = "jupyter"
for user in user_dict:
group_list = ','.join(user_dict[user])
print(f"Adding {user} who is part of groups {group_list}")
username = "-".join((prefix, user))
cmd = ["sudo", "useradd", username, "-G", group_list]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = p.communicate()
output = output.strip().decode("utf-8")
error = error.decode("utf-8")
if p.returncode != 0:
print(f"E: {error}")
else:
print(F"{user} was added")
This works, I verified by checking that users were created and assigned to their respective groups.
#check users were created
jupyter-nason_admin@ip-172-xx-xx-xxx:~$ awk -F: '$6 ~ /\/home/ {print}' /etc/passwd
syslog:x:102:106::/home/syslog:/usr/sbin/nologin
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
jupyter-nason_admin:x:1001:1003::/home/jupyter-nason_admin:/bin/sh
TEST:x:1002:1004::/home/TEST:/bin/sh
jupyter-worker_1:x:1003:1026::/home/jupyter-worker_1:/bin/sh
jupyter-worker_2:x:1004:1027::/home/jupyter-worker_2:/bin/sh
jupyter-worker_3:x:1005:1028::/home/jupyter-worker_3:/bin/sh
jupyter-worker_4:x:1006:1029::/home/jupyter-worker_4:/bin/sh
jupyter-worker_5:x:1007:1030::/home/jupyter-worker_5:/bin/sh
jupyter-worker_6:x:1008:1031::/home/jupyter-worker_6:/bin/sh
#check users were assigned to groups
jupyter-nason_admin@ip-172-xx-xx-xxx:~$ getent group
Team_Black:x:1021:jupyter-worker_5
Team_Grey:x:1022:jupyter-worker_4,jupyter-worker_6
Team_Blue:x:1023:jupyter-worker_2,jupyter-worker_4
Team_Green:x:1024:jupyter-worker_2,jupyter-worker_3
Team_Red:x:1025:jupyter-worker_1,jupyter-worker_2
My issue is that I can’t log into the users I created in this mannor, I’m guessing its because jupyterhub isnt aware of the new users created on the system. Any ideas how I can rectify this?