Read in 3 minutes
How to Delete (Remove) Users in 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 a system administrator, you have the responsibility to manage the system’s users and groups by creating new users and assign them to different groups. Occasionally, you will need to delete a user account, perhaps because that user has moved away from your organization, or the user was created for a specific service that no longer runs on the system.
In Linux, you can delete a user account and all its associated files using the userdel command. userdel is a low-level utility, Debian and Ubuntu users will more likely use the friendlier deluser utility instead.
This tutorial explains the userdel command and its options.
userdel Command Syntax
The syntax for the userdel command is as follows:
userdel [OPTIONS] USERNAME
To delete users using the userdel command you need to be logged in as root or a user with sudo access.
How to Delete User in Linux
To delete a user account named
username using the
userdel command you would run:
When invoked the userdel command reads the content of the
/etc/login.defs file. Properties defined in this file override the default behavior of the userdel command. If
USERGROUPS_ENAB is set to
yes in this file, userdel will delete the group with the same name as the user, only if no other user is a member of this group.
The command will remove the user entries from the
In most Linux distros, when removing a user account using the
userdel command the user home and mail spool directories are not removed.
--remove) option to force userdel to remove the user’s home directory and mail spool:
userdel -r username
The command above will not remove the user files located in other file systems. You will have to search for and delete the files manually.
If the user you want to remove is still logged in, or if there are running processes which belong to this user, the userdel command will not allow you to remove the user.
In this situation, it is recommended to log out the user and kill all user’s running processes with the killall command:
sudo killall -u username
Once done, you will be able to remove the user.
Another option is to use the
--force) flag that will forcefully remove the user account, even if the user is still logged in or if there are running processes which belong to this user.
userdel -f username
In this tutorial, you learned how to add delete user accounts in Linux using the userdel command. The same syntax applies for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux.
Feel free to leave a comment if you have any questions.