How to delete a user on Linux using the userdel command

Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. As the system administrator, you are responsible for managing system users and groups such as creating and assigning new users to different groups.

Sometimes you also need to delete the user account, perhaps because the user is an employee who moved from your organization, or a user created for a particular service that is no longer running on the system.

On Linux, you can delete a user account and all files associated with it using the userdel command. userdel is a low-level tool, and users of Debian and Ubuntu are more likely to use this handy deluser.

It is recommended to open the console of your Linux distribution to follow the guide on this page to better understand how it works userdel command on Linux stations.

We also recommend that you test any online tutorials or guides on a virtual machine (vmware or virtualbox) before deploying to a production server, so you don’t mess with an active system when something goes wrong.

You can learn how to install VMware on Ubuntu, CentOS, VirtualBox on Ubuntu, Fedora and CentOS

This tutorial explains the userdel command and its options.

Userdel command syntax

The syntax of the userdel command is as follows:


To delete a user using the userdel command, you must be logged in as root or a user with sudo access.

How to delete a user on Linux

To delete a user account named widarto With the userdel command, you will run:

userdel widarto

When the userdel command is called, it will read the contents of the file /etc/login.defs. The properties specified in this file override the default behavior of the userdel command.

See also  How To Install Git

if USERGROUPS_ENAB Designation yes Inside this file, userdel will delete the group with the same username, only if no other user is a member of that group.

ranking userdel It will also remove user input from the file /etc/passwd And the /etc/shadowAnd the.

On most Linux distributions, when you delete a user account using the userdel command, the user’s home directory and mail cache are not deleted.

Use option -r (--remove) To force the user to delete the user’s home directory and email store:

userdel -r widarto

The above command will not delete user files located in other file systems. You have to find and delete files manually. To manually delete files from the command line, use the rm command.

Delete users I’m still logged in.

If the user you want to delete is still logged in, or if a process is running for that user, the command userdel The user who is currently logged in will not be deleted.

In this kind of situation, it is recommended to force the user to log off and kill all user processes with the killall command:

sudo killall -u username

Another option is to use the flag -f (--force) which will forcibly delete the user’s account, even if the user is still logged in or if a process is running for that user.

userdel -f username

This position is especially useful when there is an intruder (hacker) in the system.


In this tutorial, you learned how to add and delete user accounts on Linux using the userdel command. The same formula applies to any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux.

See also  Yum commands fail with error "No module named yum" in RHEL 7

Source link

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply