Deleting unnecessary or outdated user accounts in Ubuntu 24.04 LTS is essential for maintaining security and optimizing resource use. Regular users might need to be removed due to changing roles or deactivation, and administrators require robust ways to manage these accounts seamlessly. This task is crucial for managing access permissions and ensuring system efficiency, protecting against potential security risks, and keeping the system organized.
Also, read How to add users in Ubuntu 24.04 LTS.
How to Delete Users in Ubuntu 24.04 LTS
Ubuntu 24.04 LTS offers diverse methods for deleting users, accommodating various preferences and needs. Whether you prefer the precision of terminal commands or the convenience of a graphical interface, this guide covers it all. In this comprehensive guide, we will explore multiple methods for deleting users in Ubuntu 24.04 LTS, including:
- Using the Command Line: Employing powerful commands like userdel and deluser for detailed and controlled user removal.
- Using the Graphical User Interface (GUI): Managing user accounts through Ubuntu’s intuitive settings interface.
- Manually Editing System Files: Directly editing configuration files for advanced control.
Each method is detailed with step-by-step instructions to ensure you can delete users effectively and effortlessly, enhancing your Ubuntu experience.
Method 1: Deleting a User Using the Command Line
This method is ideal for administrators who prefer using terminal commands.
a. Using userdel
The userdel command is a fundamental tool for removing user accounts in Ubuntu.
Step 1: Open the Terminal
To access the terminal, simultaneously press the Ctrl, Alt, and T keys. Alternatively, search for “Terminal” in your application menu.
Step 2: Delete the User
Execute the following command to delete a user account without removing the user’s home directory and files:
sudo userdel username
Replace the username with the specific username you intend to remove.
Step 3: Delete User with Home Directory
Use the -r (or –remove) option to remove a user account along with the user’s home directory as shown below:
sudo userdel -r username
Step 4: Force Deletion
To force the deletion of a user account that might still have running processes, use the -f (or –force) option:
sudo userdel -f username
b. Using deluser
The deluser command provides additional functionality compared to userdel.
Step 1: Open the Terminal
To access the terminal, simultaneously press the Ctrl, Alt, and T keys.
Step 2: Delete the User
Execute the following command to delete a user account without removing the user’s home directory:
sudo deluser username
Replace the username with the specific username you intend to remove.
Step 3: Delete User with Home Directory
To eliminate a user account along with their associated home directory, the –remove-home option will be used.
sudo deluser --remove-home username
Step 4: Delete User with All Files
To delete a user account along with the user’s home directory and files, including mail spool and any owned files in other locations, use the –remove-all-files option:
sudo deluser --remove-all-files username
Method 2: Deleting a User Using GUI (Graphical User Interface)
For those who prefer a graphical interface, Ubuntu provides an easy way to manage users through its settings.
Step 1: Open Settings
Search for “Settings” in your application menu.
Step 2: Access Users Section
In the Settings window, go to the search bar at the top and type “Users.”
Alternatively, navigate to the sidebar’s bottom and select “System.”
Click on “Users” from the options available in the System settings.
Step 3: Unlock User Management
Select the “Unlock” button in the upper right corner. Enter your administrative password and click “Authenticate.”
Step 4: Remove the User
Select the user you want to eliminate by clicking on them.
Click the “Remove User” button.
Choose whether to delete the home directory and files associated with the user.
Confirm the deletion.
Method 3: Manually Editing System Files
This method is more advanced and typically not recommended unless you are comfortable editing system files directly.
Step 1: Open /etc/passwd and /etc/shadow Files
Open /etc/passwd file in a text editor:
sudo nano /etc/passwd
Locate and delete the line corresponding to the user.
Save and close the file.
You can use the following command to verify the deletion. It won’t exist.
id username
Change the username with the username you want to remove.
Repeat the process for /etc/shadow:
sudo nano /etc/shadow
Remove the desired user as shown below.
Step 2: Optionally Edit /etc/group and /etc/gshadow
To remove any group memberships for the user:
sudo nano /etc/group
Remove the desired user as shown below.
sudo nano /etc/gshadow
Remove your desired user as given below.
Step 3: Remove the User’s Home Directory Manually
If you manually edited the files, you might need to remove the user’s home directory:
sudo rm -r /home/username
Conclusion
Deleting a user in Ubuntu 24.04 LTS can be done using various methods, each suitable for different scenarios and comfort levels. The userdel and deluser commands offer powerful options for command-line users, while the graphical interface provides an easy-to-use method for those who prefer GUI. Advanced users can also manually edit system files. Select the approach that best suits your needs and level of experience.