question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleting accounts from the command line

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
aolneycommented, Aug 29, 2021

Just deleted several hundred users with the following method:

  1. Request an API token
  2. 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()
  1. 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",
            })
  1. 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.

0reactions
JobinJohancommented, Aug 8, 2022

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 📈😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add and Delete Users Accounts With Command ...
1. Open your PC's Start menu. You can do this by clicking the Start button in the bottom left corner of your screen....
Read more >
Delete user account from command line
We can use the below commands to delete a user account using windows command prompt. To delete a user account of the local...
Read more >
Delete User Account Using Command Line - Prajwal Desai
To delete a user account you can use the control panel and navigate to user accounts and delete the account or you can...
Read more >
How can I delete user account using CMD? - [Answer] 2022
To delete a user account using CMD, type “net user username /delete” (without quotes) and press Enter. To delete a user account using...
Read more >
How to Delete a User Account in Windows 10 (6 Methods)
Press the Windows key and type “Command Prompt”. Click the first result under 'Best match'. ... In the Command Prompt interface, type net...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found