FUNDAMENTALS A Complete Guide for Beginners
Since the Linux distributions support multiple users, you can delete these extra users being the root user or, accessing root privileges. A user in Ubuntu can be deleted from either CLI(Command Line Interface) or GUI(Graphical User Interface). In this article, I will demonstrate both methods to delete user account in Ubuntu.
Key Takeaways
- Removing an active user account in Ubuntu both from CLI & GUI.
- Removing an idle user account in Ubuntu.
Requirements
- To remove a user in Ubuntu, you must either be the root user or have root/sudo privileges.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Watch 2 Methods to Delete User Account In Ubuntu
2 Methods to Delete User Account In Ubuntu
Deleting a user account in Ubuntu is one of the basic tasks. Therefore, the operating system offers two different approaches using CLI and GUI. For CLI, there are two basic commands in Linux that can be used to remove user accounts. These are: 1) deluser command and 2) userdel command. However, from GUI there is only a single approach.
You can read our Comparative Analysis of Methods to distinguish between these two methods and best pick one for your need.
Method 01: Using CLI to Delete a User Account in Ubuntu
You can easily remove a user using the deluser command or, userdel command with the sudo keyword in Ubuntu. These commands are alternatives to one another and work in a similar way. Therefore, in this example, I will illustrate deleting the Ubuntu user account “tom” using the userel command only. To do the same you can follow the steps below.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, type the following command in the command line.
sudo userdel tom
- sudo: Grants administrative privileges.
- userdel: Deletes a user account.
- jerry: Username of the user to be deleted.
➌ Press ENTER.
➍ Now, give the password of the currently logged-in user and hit ENTER.In the above image, you can see that I have deleted the user “tom” from my Ubuntu machine.
Furthermore, you can check if the user is actually deleted using the getent command.
Method 02: Using GUI to Delete a User Account in Ubuntu
If you do not have any knowledge of the commands in Linux, you can remove a user and the files from the GUI also. To perform this task you must log in as a root user or, you must have the same administrative privileges as a root user. If you have such permissions, then you can follow the given steps to delete a user from your system using GUI.
Steps to Follow >
➊ At first, click the Applications menu and then select “Settings” from the available applications. ➋ Go to the “Users” settings as shown in the image below and PRESS the Unlock button to perform actions as administrator.➌ Authenticate your user account by entering the password for the currently logged-in user.❹ SELECT the desired user account to be deleted and then CLICK the Remove user button. In this example, I will delete the user “tweety” by clicking the Remove user button under this user.➎ Now, a dialog box will appear on your screen giving multiple options regarding the deletion. You can either keep or delete the user’s home directory along with the user account. To completely remove the user SELECT the “Delete Files” option. Upon completion of the given steps, the desired user account will be removed from your system. You can modify the deletion or cancel the task from the last step.
Furthermore, you can check if the user is actually deleted using the getent command from the terminal.
- How to Delete Multiple Users in Linux? [2 Steps]
- Delete a User from an Ubuntu Server in Just 3 Steps
Comparative Analysis of Methods
Since this article introduces multiple methods for a single task, you might get confused about which one to pick. Therefore, in this section, I am presenting a comparative analysis of the two different approaches for your convenience. You can learn the advantages and disadvantages of the available methods and choose which is the best for you.
Methods | Pros | Cons |
---|---|---|
Method 1 |
|
|
Method 2 |
|
|
To sum up, it can be said that all of the methods come with their own pros and cons. Therefore, the suitable method varies from user to user. However, If you are comfortable with the CLI you can go for Method 1. On the other hand, If you do not have any idea about the Linux commands, you can use the approach through GUI as in Method 2.
Complementary Information
While learning about how to delete a user in Ubuntu, you will find the below information helpful.
How to Check Deleted User in Ubuntu
After completing the deletion of accounts, it is necessary to verify if the user is actually removed from the system. For this, you can use the getent command to look into the “passwd” file of the system where all the user information is stored. If some user has successfully deleted this file will not be any data under that name.
For example, I have deleted the user account “tom”. Now, in this section, I will check the deleted user in my Ubuntu system. You can do the same by following the steps below.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Type the following command in the command line.
getent passwd | grep tom
➌ Press ENTER. As you can see in the above image, the user “tom” does not exist. Therefore, the user has been successfully removed from the system.
Delete User With Home Directory
In Ubuntu, you can easily remove a user along with its home directory from the CLI using the deluser command with -r option. In this example, I will delete the user account “tom” from my system. To do the same follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Type the following command in the command line.
sudo deluser --remove-home user2
- sudo: Grants administrative privileges.
- deluser: Deletes a user account.
- –remove-home: Removes home directory and its contents.
- user2: Username of the user to be deleted.
➌ Press ENTER.
➍ Give the password of the currently logged-in user and hit ENTER. In the above image, you can see that I have deleted the user “tommy” with its home directory from my Ubuntu system. Furthermore, the ls command is used to list the remaining home directories.
- Remove User from a Group Using “gpasswd” Command in 3 Steps
- How to Delete User and All Files in Ubuntu [3 Methods]
Common Challenges That May Arise: Deleting Logged in User in Ubuntu
Deleting a user in Ubuntu is really simple unless the user is in a logged-in state. In this case, for removing the user, at first, you will need to terminate the running process owned by the target user. Then you will be able to delete the user from your system. In this example, I will show you how you can terminate the processes owned by a specific user for removing the user. Follow the steps below to do the same.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, type the following command in the command line to end the logged-in user process.
sudo killall -u tom
- killall: Terminates all the running processes.
- -u: Indicates a specified process owner.
- tom: Username of the process owner.
➌ Press ENTER.
➍ Now, give the password of the currently logged-in user and hit ENTER.
➎ Additionally, use the command below to check if the process has ended.
sudo ps -U tom
- sudo: Grants administrative privileges.
- ps: Lists running processes.
- -U: Indicates a specified process owner.
- tom: Username of the process owner.
In the above image you can see that the userdel command is not working since the user “tom” is currently running a process. Therefore, I have terminated the user’s running process. Now, the user account can be deleted from Ubuntu with the userdel command.
Conclusion
To conclude, this article illustrates different methods of deleting user accounts from both CLI and GUI in Ubuntu. Moreover, the article demonstrates the termination of the running process for removing a user. Users of beginner to advanced levels can use the explained methods to achieve this goal. Hence, following this guide will aid their journey in Linux.
People Also Ask
Related Articles