Deleting a user from your system or server via a python script is a very easy task. You just need to pass the username of the user and the script will remove the details and all the files of that user.This python script uses userdel Linux command to delete the user.You can directly use userdel command if you remember the command but if you don’t then the script makes it easy to delete the user.
The script we are about to build will ask the username of the user to be deleted as follows,
Enter Username: John
User successfully deleted with given credentials
Before running the script first we will show the user we want to delete.
cat /etc/paswd will list all the users on your system or server.John is the user we will be deleting.
The below Python code is the script we will be using for our purpose.
After running the script it will prompt for the username we want to delete and after entering the name the same user will be removed from the system.
After if we check by typing
cat/etc/passwd we can see that the user “John” is no longer on that list. So we have successfully deleted our user.
- Add a User in Linux using Python Script
- Run python script from anywhere in linux
- PyQt5 QSpinBox – Deleting it according to user
- script command in Linux with Examples
- How to Install Lazy Script in Kali Linux?
- Bash Script to get Low Battery Alert in Linux
- User Management in Linux
- Anonymity and Privacy For Linux User
- Creating a User With an Expiry Date in Linux
- How to create a Shared Folder between two Local User in Linux?
- Configure Passwordless Sudo For A Specific User in Linux
- Linux Operating System | CLI (Command Line Interface) and GUI (Graphic User Interface)
- Python | Deleting all occurrences of character
- Python | Find all possible substrings after deleting k characters
- Adding and Deleting Cookies in Selenium Python
- How to Run a Python Script
- Python Script to Shutdown Computer
- Python | Accepting Script Input
- Python Script to Restart Computer
- Get Your System Information - Using Python Script
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.