[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMay 29, 2023

How to Delete/Remove Users.

How To Delete/Remove Users.

This tutorial covers the userdel command and its options.

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 might need to delete a user account. Perhaps because the user moved away from the organization, or it 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 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:

userdel username

When invoked, the command reads the content of the /etc/login.defs file. Properties defined in this file override the default behavior of userdel. If USERGROUPS_ENAB is set to yes in this file, userdel deletes the group with the same name as the user, only if no other user is a member of this group.

The command removes the user entries from the /etc/passwd and /etc/shadow, files.

In most Linux distributions, when removing a user account with userdel, the user home and mail spool directories are not removed.

Use the -r (–remove) option to force userdel to remove the user’s home directory and mail spool:

userdel -r username

The command above does not remove the user files located in other file systems. You 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 that belong to this user, the userdel command does not allow 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 can remove the user.

Another option is to use the -f (–force) option that tells userdel to forcefully remove the user account, even if the user is still logged in or if there are running processes that belong to the user.

userdel -f username

 

Conclusion

In this tutorial, you learned how to 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.

Keep reading
Exploring the Differences Between /24 and /27
September 5, 2023

Exploring the Differences Between /24 and /27

Understanding IP Subnetting: Exploring The Differences Between /24 And /27 In the world of networking and IP addressing, subnetting plays a pivotal role in managing and organizing IP addresses effectively. Subnetting allows network administrators to divide a larger IP address space into smaller,…

Read article
How to use Docker Run Command.
September 5, 2023

How to use Docker Run Command.

How To Use Docker Run Command. In this article, we’ll use the official Nginx image to show various ways to run a Docker container. The docker run command creates a container from a given image and starts the container using a given command. It is one of the first commands you should become…

Read article
How to Set Up WireGuard VPN on Ubuntu.
September 5, 2023

How to Set Up WireGuard VPN on Ubuntu.

How To Set Up WireGuard VPN On Ubuntu. In this tutorial, we will set up WireGuard on an Ubuntu machine that will act as a VPN server. We’ll also show you how to configure WireGuard as a client. The client’s traffic will be routed through the Ubuntu 18.04 server. WireGuard is a modern VPN (Virtual…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00