Remove User in Linux Using the Command Line

How do I remove a user’s access from my Linux server? It's easy, here's how.

2
Remove User in Linux

In this article, you will learn how to remove a user in 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 at the same time. User management is an important part of Linux administration. One of the most basic tasks that you should know is how to manage the users on Linux systems.

userdel Command Syntax

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 same syntax applies for any Linux distribution, including Ubuntu, Debian, Fedora, openSUSE, Manjaro, Arch Linux, etc.

To be able 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 currently 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 with 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 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 located 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.

2 Comments

Leave a Reply

Your email address will not be published.

Latest from Linux Knowledge