the-littlest-jupyterhub
the-littlest-jupyterhub copied to clipboard
Deleting accounts from the command line
When I remove "allowed users" using tljh-config
, I noticed those users are still listed in the JupyterHub admin interface. I assume they can't log in, but is there any way to remove the users from whatever database JupyterHub is using for its internal list of users? I ask because we have to add/delete users at the end of every semester and I would really like to automate this part of the process.
@JuanCab I'm also interested in this. Have you found any workarounds or solutions?
None found yet. I ended up switching away from TLJH instead. :(
@JuanCab Ouch. OK--thanks for this info!
Just deleted several hundred users with the following method:
- Request an API token
- Create a notebook on your server with the following to get a list of users
import requests
token = 'your-magic-token'
api_url = 'https://your.domain.com/hub/api'
r = requests.get(api_url + '/users',
headers={
'Authorization': 'token %s' % token,
"Content-Type": "application/json",
}
)
r.raise_for_status()
users = r.json()
- Delete users. Code below assumes a matching name prefix, but this could be replaced with a given list of names
matching_users = [u['name'] for u in users if u['name'].startswith('e1')]
for u in matching_users:
requests.delete(api_url + "/users/" + u,
headers={
'Authorization': 'token %s' % token,
"Content-Type": "application/json",
})
- Check in your admin console that the users are gone. You may need to reload the page.
This isn't quite as easy as the command line, but it's not too bad.
I wrote a bash script that completely removes a user from the command line. You can find it here: https://github.com/JobinJohan/jupyterhub-utility-scripts.
More precisely, when deleting a user, the delete-user-from-system.sh script deletes:
- All records related to the user in the
jupyterhub.sqlite
database. - The linux account of the user (showed in
/etc/passwd
). - The
/home
folder of the user and all its content.
Hope it helps 📈😀