USERDEL(8)
๐ USERDEL(8) โ System Management Commands ๐
okay bestie, welcome to USERDEL, section 8 of the System Management Commands girlies. this is the one that says bye-bye to a user account. let's get into it ๐
โจ NAME โจ
userdel โ delete a user account and related files. that's it, that's the whole job. she's a deleter. ๐
โจ SYNOPSIS โจ
userdel [options] LOGIN
โจ DESCRIPTION โจ
so like, userdel goes into your system account files and yeets every single entry that refers to the user name LOGIN. all of them. gone. ๐
one tiny catch tho โ the user you're naming has to actually exist first. you can't delete a ghost, bestie. ๐ป
โจ OPTIONS โจ
here's everything she takes. every single one, no skips:
-f,--forceโ forces the removal of the user account and any other requested actions, straight up skipping all the safety checks. she does not ask, she does not warn, she just goes.
โ ๏ธ note: this option is dangerous and may leave your system in an inconsistent state. like, genuinely. this is not a drill. ๐จ
-h,--helpโ shows you the help message and dips out. the classic. ๐ซถ-r,--removeโ this one is the real cleanup queen. files in the user's home directory get removed along with the home directory itself, AND the user's mail spool. but heads up bestie โ files chilling in other file systems? you're gonna have to go search for those and delete them manually. she's not chasing those down for you. ๐งน
the mail spool is defined by the MAIL_DIR variable in the login.defs file. iykyk.
-R,--root CHROOT_DIRโ applies changes in theCHROOT_DIRdirectory and pulls the configuration files from theCHROOT_DIRdirectory too. only absolute paths are supported here. and nope, no SELINUX support. ๐-P,--prefix PREFIX_DIRโ applies changes in thePREFIX_DIRdirectory and uses the config files from thePREFIX_DIRdirectory. important: this one does not chroot, and it's intended for preparing a cross-compilation target. some limitations, bestie: NIS and LDAP users/groups are not verified, PAM authentication uses the host files, and there's no SELINUX support. ๐ธ-Z,--selinux-userโ removes any SELinux user mapping for the user's login. bye mapping ๐
โจ CONFIGURATION โจ
these are the config variables in /etc/login.defs that change how this tool behaves. the lore, if you will:
MAIL_DIR (string)
the mail spool directory. this is needed to manipulate the mailbox when its corresponding user account is modified or deleted. if it's not specified, a compile-time default is used. also, the parameter CREATE_MAIL_SPOOL in /etc/default/useradd decides whether the mail spool should be created in the first place. ๐
MAIL_FILE (string)
defines where the user's mail spool files live, relative to their home directory.
and fyi: the MAIL_DIR and MAIL_FILE variables are used by useradd, usermod, and userdel to create, move, or delete the user's mail spool. shared custody. ๐ค
MAX_MEMBERS_PER_GROUP (number)
maximum members per group entry. when the max is reached, a new group entry (line) gets started in /etc/group โ with the same name, same password, and same GID. iconic, honestly.
the default value is 0, meaning there are no limits on the number of members in a group.
this feature (split group) lets you limit how long the lines in the group file can get. super useful for making sure lines for NIS groups don't blow past 1024 characters.
if you genuinely need to enforce that limit, you can use 25.
โ ๏ธ note: split groups may not be supported by all tools (even inside the Shadow toolsuite). you should not use this variable unless you really need it. fr fr.
USERDEL_CMD (string)
if it's defined, this command runs when removing a user. it should remove any at/cron/print jobs etc. owned by the user being removed โ and the user gets passed in as the first argument. ๐ซถ
the return code of the script is not taken into account. she simply does not care.
here's an example script that removes the user's cron, at and print jobs:
#! /bin/sh
# Check for the required argument.
if [ $# != 1 ]; then
echo "Usage: $0 username"
exit 1
fi
# Remove cron jobs.
crontab -r -u $1
# Remove at jobs.
# Note that it will remove any jobs owned by the same UID,
# even if it was shared by a different username.
AT_SPOOL_DIR=/var/spool/cron/atjobs
find $AT_SPOOL_DIR -name "[^.]*" -type f -user $1 -delete \;
# Remove print jobs.
lprm $1
# All done.
exit 0
USERGROUPS_ENAB (boolean)
if it's set to yes, userdel will remove the user's group if it contains no more members, and useradd will create by default a group with the name of the user. the little duo doing their thing โจ
โจ FILES โจ
the whole roster of files she touches:
/etc/groupโ group account information./etc/login.defsโ shadow password suite configuration./etc/passwdโ user account information./etc/shadowโ secure user account information./etc/shadow-maint/userdel-pre.d/*,/etc/shadow-maint/userdel-post.d/*โ run-part files to execute during user deletion. the environment variableACTIONwill be populated withuserdelandSUBJECTwith the username.userdel-pre.dwill be executed prior to any user deletion.userdel-post.dwill execute after user deletion. if a script exits non-zero then execution will terminate. ๐/etc/subgidโ per user subordinate group IDs./etc/subuidโ per user subordinate user IDs.
โจ EXIT VALUES โจ
she exits with these values, so pay attention:
0โ success. slay. ๐1โ can't update password file2โ invalid command syntax6โ specified user doesn't exist8โ user currently logged in10โ can't update group file12โ can't remove home directory
โจ CAVEATS โจ
okay this is the part where we get real with each other:
userdel will not let you remove an account if there are running processes that belong to it. in that case you may have to kill those processes, or lock the user's password or account and remove the account later. the -f option can force the deletion of this account. ๐
you should manually check all file systems to make sure no files remain owned by this user. she's thorough but she's not omniscient, bestie.
you may not remove any NIS attributes on a NIS client. that has to be done on the NIS server. periodt.
if USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will delete the group with the same name as the user. to avoid inconsistencies in the passwd and group databases, userdel will check that this group is not used as a primary group for another user, and will just warn without deleting the group otherwise. the -f option can force the deletion of this group. so basically: she double-checks before she goes feral. ๐
โจ SEE ALSO โจ
go read these next, they're all in the family:
chfn(1), chsh(1), passwd(1), login.defs(5), gpasswd(8), groupadd(8), groupdel(8), groupmod(8), subgid(5), subuid(5), useradd(8), usermod(8).
and that's the whole page bestie!! ๐โจ
this lil masterpiece is from shadow-utils 4.20.0, dated 07/30/2026. go forth and delete responsibly, mwah ๐ซถ๐๐ฆ
๐ฆ where this page comes from
- arch rolling: shadow 4.20.0.arch1-1 ยท 0BSD AND BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms