In this article, you’ll learn how to remove users from a Linux system. This article describes commands and their options.
Linux is known to be a multi-user system, meaning that multiple users can interact with the same system at the same time. User management is an important part of Linux administration. One of the most basic tasks you should know is how to manage users on a Linux system.
Syntax of the userdel command The userdel command in Linux is a starter utility for deleting user accounts and related files. This command modifies the system account file to delete all entries that reference USERNAME. Userdel [OPTIONS] USERNAME The same syntax applies to any Linux distribution, including Ubuntu, Debian, Fedora, openSUSE, Manjaro, Arch Linux, etc. In order for userdel to delete a user using this command in Linux, you need to log in as root or as a user with sudo access.
Delete a user in Linux
For example, to delete a user named “Linux” from a Linux system, enter:
userdel linux
The diagram below:
Remember, userdel this command will not work if the user is currently logged in or running processes under that account. In this case, you must use -f to force the delete option. userdel -f linux
Delete a user with a home directory in Linux
When your userdel runs a command without specifying any options on the command line, the user’s home directory and associated files remain in the system. To delete the user named “Linux” and its home directory and related files, run the userdel command with the -r option. Syntax: userdel [-r] User name Parameter: -r Used for complete deletion. The files in the user’s HOME directory are removed. The files in other locations are also found and deleted, for example, the mail in /var/mailer/user name. Warning: Userdel does not allow you to remove user accounts while online. To delete an account, you must kill the program that the account is currently executing on the system. Userdel -r Linux Please note that user files located on other file systems must be searched and deleted manually.