How to Delete User Account In Ubuntu? [2 Methods]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

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

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSFlowchart of Ubuntu Delete User Account.

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
EXPLANATION
  • 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.Delete user in Ubuntu from CLIIn 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.Navigating to settings ➋  Go to the “Users” settings as shown in the image below and PRESS the Unlock button to perform actions as administrator.Selecting user settings and unlocking admin privilegesAuthenticate your user account by entering the password for the currently logged-in user.Root user authenticationSELECT 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.Delete user in Ubuntu from GUI➎ 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.Deleting user with files from GUI 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.Remaining users in Ubuntu system

Furthermore, you can check if the user is actually deleted using the getent command from the terminal.



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
  • Requires only a single command to complete the whole task.
  • A much faster approach.
  • Requires prior knowledge of the command line.

 

Method 2
  • Does not require any prior knowledge. Therefore, a more user-friendly approach.
  • A much more lengthy and time-consuming procedure.

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
EXPLANATION
  • getent: Looks into the administrative database that is given as its argument.
  • passwd: Contains user information.
  • Pipe (|): Redirects the standard output.
  • grep: Looks for a specific pattern given to it as an argument.
  • tom: Username of the deleted user account.

➌ Press ENTER.Checking user deletion in Ubuntu 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
EXPLANATION
  • 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.Deleting user with home directory 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.



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
EXPLANATION
  • 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
EXPLANATION
  • sudo: Grants administrative privileges.
  • ps: Lists running processes.
  • -U: Indicates a specified process owner.
  • tom: Username of the process owner.

Terminating user process for account deletion.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

What is the userdel command in Ubuntu?
The userdel command in Ubuntu is used to delete a user and files from the system. Moreover, this command modifies the specified system account files.
How remove user from group in Ubuntu?
To remove a user from a group, you can use the deluser command. The syntax for this command is as follows: sudo deluser USER_NAME GROUP_NAME
How do I see all users in Ubuntu?
The list of all users in Ubuntu is can be found on the “/etc/passwd” in Ubuntu. You can see extract the users from this file with the following command: cut -d: -f1 /etc/passwd.
Who is admin user in Linux?
The root user is the admin user in Linux. In general, it is the user account created while setting up the Linux distribution.
How to create user Ubuntu?
To create a user in Ubuntu, you can use the adduser or, useradd command. The adduser command is commonly used since it also creates a home directory for the user.

Related Articles

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment