search
HomeOperation and MaintenanceWindows Operation and MaintenanceHow to use the userdel command to delete a user in Linux? (code example)

Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. So what do you do if you need to delete a user's account? The following article will show you how to use the userdel command to delete users in Linux. I hope it will be helpful to you.

How to use the userdel command to delete a user in Linux? (code example)

Linux userdel command

In Linux, administrators can use the userdel command to delete user accounts and all its associated files.

Let’s take a look at the userdel command syntax:

userdel [OPTIONS] USERNAME

To use the userdel command to delete a user, the user needs to be logged in as root or as a user with sudo access.

How to delete a user in Linux?

To use the userdel command to delete the user account named "username", you need to run the following command:

userdel username

When the userdel command is called, /etc is read The contents of the /login.defs file. Properties defined in this file override the default behavior of the userdel command. If "USERGROUPS_ENAB" in this file is set to "yes", userdel will only delete groups with the same name as the user if other users are not members of this group.

Description: The userdel command will delete user entries from the /etc/passwd and /etc/shadow files.

In most Linux distributions, when you use the userdel command to delete a user account, the user's home directory and mail spool directory will not be deleted.

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

userdel -r username

Note: The above command will not delete it User files located in other file systems.

If the user to be deleted is still logged in, or if there are running processes belonging to that user, the userdel command will not allow the user to be deleted.

In this case, it is recommended to use the killall command to log out the user and terminate all running processes of the user:

sudo killall -u username

Once completed, you will be able to delete the user.

Another option is to use the -f (--force) flag to force deletion of a user account even if the user is still logged in or there are running processes belonging to that user.

userdel -f username

Recommended related video tutorials: "Linux Tutorial"

The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to use the userdel command to delete a user in Linux? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment