[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
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
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

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

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

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM