1USERDEL(8)                System Management Commands                USERDEL(8)
2
3
4

NAME

6       userdel - delete a user account and related files
7

SYNOPSIS

9       userdel [options] LOGIN
10

DESCRIPTION

12       The userdel command modifies the system account files, deleting all
13       entries that refer to the user name LOGIN. The named user must exist.
14

OPTIONS

16       The options which apply to the userdel command are:
17
18       -f, --force
19           This option forces the removal of the user account, even if the
20           user is still logged in. It also forces userdel to remove the
21           user's home directory and mail spool, even if another user uses the
22           same home directory or if the mail spool is not owned by the
23           specified user. If USERGROUPS_ENAB is defined to yes in
24           /etc/login.defs and if a group exists with the same name as the
25           deleted user, then this group will be removed, even if it is still
26           the primary group of another user.
27
28           Note: This option is dangerous and may leave your system in an
29           inconsistent state.
30
31       -h, --help
32           Display help message and exit.
33
34       -r, --remove
35           Files in the user's home directory will be removed along with the
36           home directory itself and the user's mail spool. Files located in
37           other file systems will have to be searched for and deleted
38           manually.
39
40           The mail spool is defined by the MAIL_DIR variable in the
41           login.defs file.
42
43       -R, --root CHROOT_DIR
44           Apply changes in the CHROOT_DIR directory and use the configuration
45           files from the CHROOT_DIR directory.
46
47       -P, --prefix PREFIX_DIR
48           Apply changes in the PREFIX_DIR directory and use the configuration
49           files from the PREFIX_DIR directory. This option does not chroot
50           and is intended for preparing a cross-compilation target. Some
51           limitations: NIS and LDAP users/groups are not verified. PAM
52           authentication is using the host files. No SELINUX support.
53
54       -Z, --selinux-user
55           Remove any SELinux user mapping for the user's login.
56

CONFIGURATION

58       The following configuration variables in /etc/login.defs change the
59       behavior of this tool:
60
61       MAIL_DIR (string)
62           The mail spool directory. This is needed to manipulate the mailbox
63           when its corresponding user account is modified or deleted. If not
64           specified, a compile-time default is used. The parameter
65           CREATE_MAIL_SPOOL in /etc/default/useradd determines whether the
66           mail spool should be created.
67
68       MAIL_FILE (string)
69           Defines the location of the users mail spool files relatively to
70           their home directory.
71
72       The MAIL_DIR and MAIL_FILE variables are used by useradd, usermod, and
73       userdel to create, move, or delete the user's mail spool.
74
75       If MAIL_CHECK_ENAB is set to yes, they are also used to define the MAIL
76       environment variable.
77
78       MAX_MEMBERS_PER_GROUP (number)
79           Maximum members per group entry. When the maximum is reached, a new
80           group entry (line) is started in /etc/group (with the same name,
81           same password, and same GID).
82
83           The default value is 0, meaning that there are no limits in the
84           number of members in a group.
85
86           This feature (split group) permits to limit the length of lines in
87           the group file. This is useful to make sure that lines for NIS
88           groups are not larger than 1024 characters.
89
90           If you need to enforce such limit, you can use 25.
91
92           Note: split groups may not be supported by all tools (even in the
93           Shadow toolsuite). You should not use this variable unless you
94           really need it.
95
96       USERDEL_CMD (string)
97           If defined, this command is run when removing a user. It should
98           remove any at/cron/print jobs etc. owned by the user to be removed
99           (passed as the first argument).
100
101           The return code of the script is not taken into account.
102
103           Here is an example script, which removes the user's cron, at and
104           print jobs:
105
106               #! /bin/sh
107
108               # Check for the required argument.
109               if [ $# != 1 ]; then
110                    echo "Usage: $0 username"
111                    exit 1
112               fi
113
114               # Remove cron jobs.
115               crontab -r -u $1
116
117               # Remove at jobs.
118               # Note that it will remove any jobs owned by the same UID,
119               # even if it was shared by a different username.
120               AT_SPOOL_DIR=/var/spool/cron/atjobs
121               find $AT_SPOOL_DIR -name "[^.]*" -type f -user $1 -delete \;
122
123               # Remove print jobs.
124               lprm $1
125
126               # All done.
127               exit 0
128
129
130
131       USERGROUPS_ENAB (boolean)
132           Enable setting of the umask group bits to be the same as owner bits
133           (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid
134           is the same as gid, and username is the same as the primary group
135           name.
136
137           If set to yes, userdel will remove the user's group if it contains
138           no more members, and useradd will create by default a group with
139           the name of the user.
140

FILES

142       /etc/group
143           Group account information.
144
145       /etc/login.defs
146           Shadow password suite configuration.
147
148       /etc/passwd
149           User account information.
150
151       /etc/shadow
152           Secure user account information.
153
154       /etc/shadow-maint/userdel-pre.d/*, /etc/shadow-maint/userdel-post.d/*
155           Run-part files to execute during user deletion. The environment
156           variable ACTION will be populated with userdel and SUBJECT with the
157           username.  userdel-pre.d will be executed prior to any user
158           deletion.  userdel-post.d will execute after user deletion. If a
159           script exits non-zero then execution will terminate.
160
161       /etc/subgid
162           Per user subordinate group IDs.
163
164       /etc/subuid
165           Per user subordinate user IDs.
166

EXIT VALUES

168       The userdel command exits with the following values:
169
170       0
171           success
172
173       1
174           can't update password file
175
176       2
177           invalid command syntax
178
179       6
180           specified user doesn't exist
181
182       8
183           user currently logged in
184
185       10
186           can't update group file
187
188       12
189           can't remove home directory
190

CAVEATS

192       userdel will not allow you to remove an account if there are running
193       processes which belong to this account. In that case, you may have to
194       kill those processes or lock the user's password or account and remove
195       the account later. The -f option can force the deletion of this
196       account.
197
198       You should manually check all file systems to ensure that no files
199       remain owned by this user.
200
201       You may not remove any NIS attributes on a NIS client. This must be
202       performed on the NIS server.
203
204       If USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will
205       delete the group with the same name as the user. To avoid
206       inconsistencies in the passwd and group databases, userdel will check
207       that this group is not used as a primary group for another user, and
208       will just warn without deleting the group otherwise. The -f option can
209       force the deletion of this group.
210

SEE ALSO

212       chfn(1), chsh(1), passwd(1), login.defs(5), gpasswd(8), groupadd(8),
213       groupdel(8), groupmod(8), subgid(5), subuid(5), useradd(8), usermod(8).
214
215
216
217shadow-utils 4.11.1               02/10/2022                        USERDEL(8)
Impressum