In this article, you will learn how to remove a user in a Linux system. The article covers the userdel command and its options.
As you know, Linux is a multi-user system, which means that more than one user can interact with the same system simultaneously.
Therefore, user management is an essential part of Linux administration. Hence, one of the most basic tasks you should know is managing the Linux systems’ users.
userdel Command Syntax
The userdel command in Linux is a low-level utility used to remove a user account and related files. The command modifies the system account files, deleting all entries that refer to USERNAME.
userdel [OPTIONS] USERNAME
The exact syntax applies to any Linux distribution, including Ubuntu, Debian, Fedora, openSUSE, Manjaro, Arch Linux, etc.
To remove users using the userdel
command in Linux, you need to be logged in as root or a user with sudo access.
Remove User in Linux
For example, if you want to remove a user named ‘john‘ from your Linux system, enter:
userdel john
Keep in mind that the userdel
command won’t work if the user is logged in or has processes running under the account. In this case, you must use the -f
option to force deletion.
userdel -f john
Remove User along with Their Home Directory in Linux
When you run a userdel
command without any options specified in the command line, the user’s home directory and mail spool will remain in the system.
To remove the user named john
along with its home directory and mail spool, execute the userdel
command with the -r
option.
userdel -r john
Files in the user’s home directory will be removed along with the home directory itself and the user’s mail spool.
Please note that the user’s files in other file systems will have to be searched for and deleted manually.
For more detailed information about the userdel
command, you can head to the command’s man page.
So what happens if one does “userdel -f root” ?
you will be doomed