1USERADD(8) System Management Commands USERADD(8)
2
3
4
6 useradd - create a new user or update default new user information
7
9 useradd [options] LOGIN
10
11 useradd -D
12
13 useradd -D [options]
14
16 When invoked without the -D option, the useradd command creates a new
17 user account using the values specified on the command line plus the
18 default values from the system. Depending on command line options, the
19 useradd command will update system files and may also create the new
20 user´s home directory and copy initial files.
21
22 By default, a group will also be created for the new user (see -g, -N,
23 -U, and USERGROUPS_ENAB).
24
26 The options which apply to the useradd command are:
27
28 -b, --base-dir BASE_DIR
29 The default base directory for the system if -d HOME_DIR is not
30 specified. BASE_DIR is concatenated with the account name to
31 define the home directory. The BASE_DIR must exist otherwise the
32 home directory cannot be created.
33
34 If this option is not specified, useradd will use the base
35 directory specified by the HOME variable in /etc/default/useradd,
36 or /home by default.
37
38 -c, --comment COMMENT
39 Any text string. It is generally a short description of the login,
40 and is currently used as the field for the user´s full name.
41
42 -d, --home-dir HOME_DIR
43 The new user will be created using HOME_DIR as the value for the
44 user´s login directory. The default is to append the LOGIN name to
45 BASE_DIR and use that as the login directory name.
46
47 -D, --defaults
48 See below, the subsection "Changing the default values".
49
50 -e, --expiredate EXPIRE_DATE
51 The date on which the user account will be disabled. The date is
52 specified in the format YYYY-MM-DD.
53
54 If not specified, useradd will use the default expiry date
55 specified by the EXPIRE variable in /etc/default/useradd, or an
56 empty string (no expiry) by default.
57
58 -f, --inactive INACTIVE
59 The number of days after a password expires until the account is
60 permanently disabled. A value of 0 disables the account as soon as
61 the password has expired, and a value of -1 disables the feature.
62
63 If not specified, useradd will use the default inactivity period
64 specified by the INACTIVE variable in /etc/default/useradd, or -1
65 by default.
66
67 -g, --gid GROUP
68 The group name or number of the user´s initial login group. The
69 group name must exist. A group number must refer to an already
70 existing group.
71
72 If not specified, the behavior of useradd will depend on the
73 USERGROUPS_ENAB variable in /etc/login.defs. If this variable is
74 set to yes (or -U/--user-group is specified on the command line), a
75 group will be created for the user, with the same name as her
76 loginname. If the variable is set to no (or -N/--no-user-group is
77 specified on the command line), useradd will set the primary group
78 of the new user to the value specified by the GROUP variable in
79 /etc/default/useradd, or 100 by default.
80
81 -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
82 A list of supplementary groups which the user is also a member of.
83 Each group is separated from the next by a comma, with no
84 intervening whitespace. The groups are subject to the same
85 restrictions as the group given with the -g option. The default is
86 for the user to belong only to the initial group.
87
88 -h, --help
89 Display help message and exit.
90
91 -k, --skel SKEL_DIR
92 The skeleton directory, which contains files and directories to be
93 copied in the user´s home directory, when the home directory is
94 created by useradd.
95
96 This option is only valid if the -m (or --create-home) option is
97 specified.
98
99 If this option is not set, the skeleton directory is defined by the
100 SKEL variable in /etc/default/useradd or, by default, /etc/skel.
101
102 If possible, the ACLs and extended attributes are copied.
103
104 -K, --key KEY=VALUE
105 Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK,
106 PASS_MAX_DAYS and others).
107
108 Example: -K PASS_MAX_DAYS=-1 can be used when creating system
109 account to turn off password ageing, even though system account has
110 no password at all. Multiple -K options can be specified, e.g.: -K
111 UID_MIN=100 -K UID_MAX=499
112
113 -l, --no-log-init
114 Do not add the user to the lastlog and faillog databases.
115
116 By default, the user´s entries in the lastlog and faillog databases
117 are resetted to avoid reusing the entry from a previously deleted
118 user.
119
120 -m, --create-home
121 Create the user´s home directory if it does not exist. The files
122 and directories contained in the skeleton directory (which can be
123 defined with the -k option) will be copied to the home directory.
124
125 By default, if this option is not specified and CREATE_HOME is not
126 enabled, no home directories are created.
127
128 The directory where the user´s home directory is created must exist
129 and have proper SELinux context and permissions. Otherwise the
130 user´s home directory cannot be created or accessed.
131
132 -M, --no-create-home
133 Do not create the user´s home directory, even if the system wide
134 setting from /etc/login.defs (CREATE_HOME) is set to yes.
135
136 -N, --no-user-group
137 Do not create a group with the same name as the user, but add the
138 user to the group specified by the -g option or by the GROUP
139 variable in /etc/default/useradd.
140
141 The default behavior (if the -g, -N, and -U options are not
142 specified) is defined by the USERGROUPS_ENAB variable in
143 /etc/login.defs.
144
145 -o, --non-unique
146 Allow the creation of a user account with a duplicate (non-unique)
147 UID.
148
149 This option is only valid in combination with the -u option.
150
151 -p, --password PASSWORD
152 The encrypted password, as returned by crypt(3). The default is to
153 disable the password.
154
155
156 Note: This option is not recommended because the password (or
157 encrypted password) will be visible by users listing the processes.
158
159 You should make sure the password respects the system´s password
160 policy.
161
162 -r, --system
163 Create a system account.
164
165 System users will be created with no aging information in
166 /etc/shadow, and their numeric identifiers are chosen in the
167 SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead
168 of UID_MIN-UID_MAX (and their GID counterparts for the creation of
169 groups).
170
171 Note that useradd will not create a home directory for such an
172 user, regardless of the default setting in /etc/login.defs
173 (CREATE_HOME). You have to specify the -m options if you want a
174 home directory for a system account to be created.
175
176 -R, --root CHROOT_DIR
177 Apply changes in the CHROOT_DIR directory and use the configuration
178 files from the CHROOT_DIR directory.
179
180 -s, --shell SHELL
181 The name of the user´s login shell. The default is to leave this
182 field blank, which causes the system to select the default login
183 shell specified by the SHELL variable in /etc/default/useradd, or
184 an empty string by default.
185
186 -u, --uid UID
187 The numerical value of the user´s ID. This value must be unique,
188 unless the -o option is used. The value must be non-negative. The
189 default is to use the smallest ID value greater than or equal to
190 UID_MIN and greater than every other user.
191
192 See also the -r option and the UID_MAX description.
193
194 -U, --user-group
195 Create a group with the same name as the user, and add the user to
196 this group.
197
198 The default behavior (if the -g, -N, and -U options are not
199 specified) is defined by the USERGROUPS_ENAB variable in
200 /etc/login.defs.
201
202 -Z, --selinux-user SEUSER
203 The SELinux user for the user´s login. The default is to leave this
204 field blank, which causes the system to select the default SELinux
205 user.
206
207 Changing the default values
208 When invoked with only the -D option, useradd will display the current
209 default values. When invoked with -D plus other options, useradd will
210 update the default values for the specified options. Valid
211 default-changing options are:
212
213 -b, --base-dir BASE_DIR
214 The path prefix for a new user´s home directory. The user´s name
215 will be affixed to the end of BASE_DIR to form the new user´s home
216 directory name, if the -d option is not used when creating a new
217 account.
218
219 This option sets the HOME variable in /etc/default/useradd.
220
221 -e, --expiredate EXPIRE_DATE
222 The date on which the user account is disabled.
223
224 This option sets the EXPIRE variable in /etc/default/useradd.
225
226 -f, --inactive INACTIVE
227 The number of days after a password has expired before the account
228 will be disabled.
229
230 This option sets the INACTIVE variable in /etc/default/useradd.
231
232 -g, --gid GROUP
233 The group name or ID for a new user´s initial group (when the
234 -N/--no-user-group is used or when the USERGROUPS_ENAB variable is
235 set to no in /etc/login.defs). The named group must exist, and a
236 numerical group ID must have an existing entry.
237
238 This option sets the GROUP variable in /etc/default/useradd.
239
240 -s, --shell SHELL
241 The name of a new user´s login shell.
242
243 This option sets the SHELL variable in /etc/default/useradd.
244
246 The system administrator is responsible for placing the default user
247 files in the /etc/skel/ directory (or any other skeleton directory
248 specified in /etc/default/useradd or on the command line).
249
251 You may not add a user to a NIS or LDAP group. This must be performed
252 on the corresponding server.
253
254 Similarly, if the username already exists in an external user database
255 such as NIS or LDAP, useradd will deny the user account creation
256 request.
257
258 Usernames may only be up to 32 characters long.
259
261 The following configuration variables in /etc/login.defs change the
262 behavior of this tool:
263
264 CREATE_HOME (boolean)
265 Indicate if a home directory should be created by default for new
266 users.
267
268 This setting does not apply to system users, and can be overridden
269 on the command line.
270
271 GID_MAX (number), GID_MIN (number)
272 Range of group IDs used for the creation of regular groups by
273 useradd, groupadd, or newusers.
274
275 The default value for GID_MIN (resp. GID_MAX) is 500 (resp.
276 60000).
277
278 MAIL_DIR (string)
279 The mail spool directory. This is needed to manipulate the mailbox
280 when its corresponding user account is modified or deleted. If not
281 specified, a compile-time default is used.
282
283 MAIL_FILE (string)
284 Defines the location of the users mail spool files relatively to
285 their home directory.
286
287 The MAIL_DIR and MAIL_FILE variables are used by useradd, usermod, and
288 userdel to create, move, or delete the user´s mail spool.
289
290 If MAIL_CHECK_ENAB is set to yes, they are also used to define the MAIL
291 environment variable.
292
293 MAX_MEMBERS_PER_GROUP (number)
294 Maximum members per group entry. When the maximum is reached, a new
295 group entry (line) is started in /etc/group (with the same name,
296 same password, and same GID).
297
298 The default value is 0, meaning that there are no limits in the
299 number of members in a group.
300
301 This feature (split group) permits to limit the length of lines in
302 the group file. This is useful to make sure that lines for NIS
303 groups are not larger than 1024 characters.
304
305 If you need to enforce such limit, you can use 25.
306
307 Note: split groups may not be supported by all tools (even in the
308 Shadow toolsuite). You should not use this variable unless you
309 really need it.
310
311 PASS_MAX_DAYS (number)
312 The maximum number of days a password may be used. If the password
313 is older than this, a password change will be forced. If not
314 specified, -1 will be assumed (which disables the restriction).
315
316 PASS_MIN_DAYS (number)
317 The minimum number of days allowed between password changes. Any
318 password changes attempted sooner than this will be rejected. If
319 not specified, -1 will be assumed (which disables the restriction).
320
321 PASS_WARN_AGE (number)
322 The number of days warning given before a password expires. A zero
323 means warning is given only upon the day of expiration, a negative
324 value means no warning is given. If not specified, no warning will
325 be provided.
326
327 SYS_GID_MAX (number), SYS_GID_MIN (number)
328 Range of group IDs used for the creation of system groups by
329 useradd, groupadd, or newusers.
330
331 The default value for SYS_GID_MIN (resp. SYS_GID_MAX) is 201
332 (resp. GID_MIN-1).
333
334 SYS_UID_MAX (number), SYS_UID_MIN (number)
335 Range of user IDs used for the creation of system users by useradd
336 or newusers.
337
338 The default value for SYS_UID_MIN (resp. SYS_UID_MAX) is 201
339 (resp. UID_MIN-1).
340
341 UID_MAX (number), UID_MIN (number)
342 Range of user IDs used for the creation of regular users by useradd
343 or newusers.
344
345 The default value for UID_MIN (resp. UID_MAX) is 500 (resp.
346 60000).
347
348 UMASK (number)
349 The file mode creation mask is initialized to this value. If not
350 specified, the mask will be initialized to 022.
351
352
353 useradd and newusers use this mask to set the mode of the home
354 directory they create
355
356 It is also used by login to define users´ initial umask. Note that
357 this mask can be overridden by the user´s GECOS line (if
358 QUOTAS_ENAB is set) or by the specification of a limit with the K
359 identifier in limits(5).
360
361 USERGROUPS_ENAB (boolean)
362 Enable setting of the umask group bits to be the same as owner bits
363 (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid
364 is the same as gid, and username is the same as the primary group
365 name.
366
367 If set to yes, userdel will remove the user´s group if it contains
368 no more members, and useradd will create by default a group with
369 the name of the user.
370
372 /etc/passwd
373 User account information.
374
375 /etc/shadow
376 Secure user account information.
377
378 /etc/group
379 Group account information.
380
381 /etc/gshadow
382 Secure group account information.
383
384 /etc/default/useradd
385 Default values for account creation.
386
387 /etc/skel/
388 Directory containing default files.
389
390 /etc/login.defs
391 Shadow password suite configuration.
392
394 The useradd command exits with the following values:
395
396 0
397 success
398
399 1
400 can´t update password file
401
402 2
403 invalid command syntax
404
405 3
406 invalid argument to option
407
408 4
409 UID already in use (and no -o)
410
411 6
412 specified group doesn´t exist
413
414 9
415 username already in use
416
417 10
418 can´t update group file
419
420 12
421 can´t create home directory
422
423 14
424 can´t update SELinux user mapping
425
427 chfn(1), chsh(1), passwd(1), crypt(3), groupadd(8), groupdel(8),
428 groupmod(8), login.defs(5), newusers(8), userdel(8), usermod(8).
429
430
431
432shadow-utils 4.1.5.1 05/10/2016 USERADD(8)