LinuxCommandLibrary

userdel

Delete user accounts

TLDR

Remove a user

$ sudo userdel [username]
copy

Remove a user in other root directory
$ sudo userdel [[-R|--root]] [path/to/other/root] [username]
copy

Remove a user along with the home directory and mail spool
$ sudo userdel [[-r|--remove]] [username]
copy

SYNOPSIS

userdel [options] username

PARAMETERS

username
    The name of the user account to delete.

-f, --force
    Force the removal of the user account, even if the user is still logged in. This can lead to unpredictable behavior, so use with caution.

-r, --remove
    Remove the user's home directory and mail spool.

-Z, --selinux-user
    Remove any SELinux user mapping for the user.

DESCRIPTION

The userdel command in Linux is used to delete a user account from the system. It removes the user's entry from the /etc/passwd, /etc/shadow, and /etc/group files, effectively preventing the user from logging in.
By default, userdel does not remove the user's home directory or mail spool. Options exist to delete these, but careful consideration is crucial before doing so, as it results in permanent data loss.
userdel is a crucial command for system administrators to manage user accounts and maintain system security.

CAVEATS

Deleting a user's home directory with -r is irreversible. Make sure to back up any important data before using this option.
Using -f can disrupt system stability if the user is actively using the system.

EXIT STATUS

The userdel command returns 0 on success, and a non-zero value on failure. Common failure reasons include the user not existing, insufficient permissions, or the user being currently logged in (and -f not used).

HISTORY

The userdel command has been a standard part of Unix-like operating systems for a long time. Its purpose remains consistent: to provide a method for removing user accounts, ensuring proper system administration and security.

SEE ALSO

useradd(8), usermod(8), groupadd(8), groupdel(8)

Copied to clipboard