]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pw/pw.8
zfs: merge openzfs/zfs@8e8acabdc
[FreeBSD/FreeBSD.git] / usr.sbin / pw / pw.8
1 .\" Copyright (C) 1996
2 .\" David L. Nugent.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd November 28, 2022
28 .Dt PW 8
29 .Os
30 .Sh NAME
31 .Nm pw
32 .Nd create, remove, modify & display system users and groups
33 .Sh SYNOPSIS
34 .Nm
35 .Op Fl R Ar rootdir
36 .Op Fl V Ar etcdir
37 .Cm useradd
38 .Oo Fl n Oc Ar name
39 .Op Fl mNoPq
40 .Op Fl C Ar config
41 .Op Fl c Ar comment
42 .Op Fl d Ar homedir
43 .Op Fl e Ar accexpdate
44 .Op Fl G Ar grouplist
45 .Op Fl g Ar group
46 .Op Fl H Ar fd
47 .Op Fl h Ar fd
48 .Op Fl k Ar skeldir
49 .Op Fl L Ar class
50 .Op Fl M Ar mode
51 .Op Fl p Ar passexpdate
52 .Op Fl s Ar shell
53 .Op Fl u Ar uid
54 .Op Fl w Ar passmethod
55 .Op Fl Y Op Fl y Ar nispasswd
56 .Nm
57 .Op Fl R Ar rootdir
58 .Op Fl V Ar etcdir
59 .Cm useradd
60 .Fl D
61 .Op Fl q
62 .Op Fl b Ar basehome
63 .Op Fl C Ar config
64 .Op Fl e Ar accexpdays
65 .Op Fl G Ar grouplist
66 .Op Fl g Ar group
67 .Op Fl i Ar mingid , Ns Ar maxgid
68 .Op Fl k Ar skeldir
69 .Op Fl M Ar mode
70 .Op Fl p Ar passexpdays
71 .Op Fl s Ar shell
72 .Op Fl u Ar minuid , Ns Ar maxuid
73 .Op Fl w Ar passmethod
74 .Op Fl Y Op Fl y Ar nispasswd
75 .Nm
76 .Op Fl R Ar rootdir
77 .Op Fl V Ar etcdir
78 .Cm userdel
79 .Oo Fl n Oc Ar name Ns | Ns Oo Fl u Oc Ar uid
80 .Op Fl r
81 .Op Fl Y Op Fl y Ar nispasswd
82 .Nm
83 .Op Fl R Ar rootdir
84 .Op Fl V Ar etcdir
85 .Cm usermod
86 .Oo Fl n Oc Ar name Ns | Ns Ar uid Oo Fl u Ar newuid Oc | Fl u Ar uid
87 .Op Fl mNPq
88 .Op Fl C Ar config
89 .Op Fl c Ar comment
90 .Op Fl d Ar homedir
91 .Op Fl e Ar accexpdate
92 .Op Fl k Ar skeldir
93 .Op Fl G Ar grouplist
94 .Op Fl g Ar group
95 .Op Fl H Ar fd
96 .Op Fl h Ar fd
97 .Op Fl L Ar class
98 .Op Fl l Ar newname
99 .Op Fl M Ar mode
100 .Op Fl p Ar passexpdate
101 .Op Fl s Ar shell
102 .Op Fl w Ar passmethod
103 .Op Fl Y Op Fl y Ar nispasswd
104 .Nm
105 .Op Fl R Ar rootdir
106 .Op Fl V Ar etcdir
107 .Cm usershow
108 .Oo Fl n Oc Ar name Ns | Ns Oo Fl u Oc Ar uid
109 .Op Fl 7aFP
110 .Nm
111 .Op Fl R Ar rootdir
112 .Op Fl V Ar etcdir
113 .Cm usernext
114 .Op Fl q
115 .Op Fl C Ar config
116 .Nm
117 .Op Fl R Ar rootdir
118 .Op Fl V Ar etcdir
119 .Cm groupadd
120 .Oo Fl n Oc Ar name
121 .Op Fl oNPqY
122 .Op Fl C Ar config
123 .Op Fl g Ar gid
124 .Op Fl H Ar fd
125 .Op Fl h Ar fd
126 .Op Fl M Ar members
127 .Nm
128 .Op Fl R Ar rootdir
129 .Op Fl V Ar etcdir
130 .Cm groupdel
131 .Oo Fl n Oc Ar name Ns | Ns Oo Fl g Oc Ar gid
132 .Op Fl Y
133 .Nm
134 .Op Fl R Ar rootdir
135 .Op Fl V Ar etcdir
136 .Cm groupmod
137 .Oo Fl n Oc Ar name Ns | Ns Ar gid Oo Fl g Ar newgid Oc | Fl g Ar gid
138 .Op Fl NPqY
139 .Op Fl C Ar config
140 .Op Fl d Ar oldmembers
141 .Op Fl H Ar fd
142 .Op Fl h Ar fd
143 .Op Fl l Ar newname
144 .Op Fl M Ar members
145 .Op Fl m Ar newmembers
146 .Nm
147 .Op Fl R Ar rootdir
148 .Op Fl V Ar etcdir
149 .Cm groupshow
150 .Oo Fl n Oc Ar name Ns | Ns Oo Fl g Oc Ar gid
151 .Op Fl aFP
152 .Nm
153 .Op Fl R Ar rootdir
154 .Op Fl V Ar etcdir
155 .Cm groupnext
156 .Op Fl C Ar config
157 .Op Fl q
158 .Nm
159 .Op Fl R Ar rootdir
160 .Op Fl V Ar etcdir
161 .Cm lock
162 .Oo Fl n Oc Ar name Ns | Ns Oo Fl u Oc Ar uid
163 .Op Fl q
164 .Op Fl C Ar config
165 .Nm
166 .Op Fl R Ar rootdir
167 .Op Fl V Ar etcdir
168 .Cm unlock
169 .Oo Fl n Oc Ar name Ns | Ns Oo Fl u Oc Ar uid
170 .Op Fl q
171 .Op Fl C Ar config
172 .Sh DESCRIPTION
173 The
174 .Nm
175 utility is a command-line based editor for the system
176 .Ar user
177 and
178 .Ar group
179 files, allowing the superuser an easy to use and standardized way of adding,
180 modifying and removing users and groups.
181 Note that
182 .Nm
183 only operates on the local user and group files.
184 .Tn NIS
185 users and groups must be
186 maintained on the
187 .Tn NIS
188 server.
189 The
190 .Nm
191 utility handles updating the
192 .Xr passwd 5 ,
193 .Xr master.passwd 5 ,
194 .Xr group 5
195 and the secure and insecure
196 password database files, and must be run as root.
197 .Pp
198 The first one or two keywords provided to
199 .Nm
200 on the command line provide the context for the remainder of the arguments.
201 The keywords
202 .Cm user
203 and
204 .Cm group
205 may be combined with
206 .Cm add ,
207 .Cm del ,
208 .Cm mod ,
209 .Cm show ,
210 or
211 .Cm next
212 in any order.
213 (For example,
214 .Cm showuser ,
215 .Cm usershow ,
216 .Cm show user ,
217 and
218 .Cm user show
219 all mean the same thing.)
220 This flexibility is useful for interactive scripts calling
221 .Nm
222 for user and group database manipulation.
223 Following these keywords,
224 the user or group name or numeric id may be optionally specified as an
225 alternative to using the
226 .Fl n Ar name ,
227 .Fl u Ar uid ,
228 .Fl g Ar gid
229 options.
230 .Pp
231 The following flags are common to most or all modes of operation:
232 .Bl -tag -width "-G grouplist"
233 .It Fl R Ar rootdir
234 Specifies an alternate root directory within which
235 .Nm
236 will operate.
237 Any paths specified will be relative to
238 .Va rootdir .
239 .It Fl V Ar etcdir
240 Set an alternate location for the password, group, and configuration files.
241 Can be used to maintain a user/group database in an alternate location.
242 If this switch is specified, the system
243 .Pa /etc/pw.conf
244 will not be sourced for default configuration data,
245 but the file
246 .Pa pw.conf
247 in the specified directory will be used instead
248 .Pq or none, if it does not exist .
249 The
250 .Fl C
251 flag may be used to override this behaviour.
252 As an exception to the general rule where options must follow the operation
253 type, the
254 .Fl V
255 flag must be used on the command line before the operation keyword.
256 .It Fl C Ar config
257 By default,
258 .Nm
259 reads the file
260 .Pa /etc/pw.conf
261 to obtain policy information on how new user accounts and groups are to be created.
262 The
263 .Fl C
264 option specifies a different configuration file.
265 While most of the contents of the configuration file may be overridden via
266 command-line options, it may be more convenient to keep standard information in a
267 configuration file.
268 .It Fl q
269 Use of this option causes
270 .Nm
271 to suppress error messages,
272 which may be useful in interactive environments where it
273 is preferable to interpret status codes returned by
274 .Nm
275 rather than messing up a carefully formatted display.
276 .It Fl N
277 This option is available in
278 .Cm add
279 and
280 .Cm modify
281 operations, and tells
282 .Nm
283 to output the result of the operation without updating the user or group
284 databases.
285 You may use the
286 .Fl P
287 option to switch between standard passwd and readable formats.
288 .It Fl Y
289 Using this option with any of the update modes causes
290 .Nm
291 to run
292 .Xr make 1
293 after changing to the directory
294 .Pa /var/yp .
295 This is intended to allow automatic updating of
296 .Tn NIS
297 database files.
298 If separate passwd and group files are being used by
299 .Tn NIS ,
300 then use the
301 .Fl y Ar nispasswd
302 option to specify the location of the
303 .Tn NIS
304 passwd database so that
305 .Nm
306 will concurrently update it with the system password
307 databases.
308 .El
309 .Sh USER OPTIONS
310 The following options apply to the
311 .Cm useradd
312 and
313 .Cm usermod
314 commands:
315 .Bl -tag -width "-G grouplist"
316 .It Oo Fl n Oc Ar name
317 Required unless
318 .Fl u Ar uid
319 is given.
320 Specify the user/account name.
321 In the case of
322 .Cm usermod
323 can be a
324 .Ar uid .
325 .It Fl u Ar uid
326 Required if
327 .Ar name
328 is not given.
329 Specify the user/account numeric id.
330 In the case of
331 .Cm usermod
332 if paired with
333 .Ar name ,
334 changes the numeric id of the named user/account.
335 .Pp
336 Usually, only one of these options is required,
337 as the account name will imply the uid, or vice versa.
338 However, there are times when both are needed.
339 For example, when changing the uid of an existing user with
340 .Cm usermod ,
341 or overriding the default uid when creating a new account with
342 .Cm useradd .
343 To automatically allocate the uid to a new user with
344 .Cm useradd ,
345 then do
346 .Em not
347 use the
348 .Fl u
349 option.
350 Either the account or userid can also be provided immediately after the
351 .Cm useradd ,
352 .Cm userdel ,
353 .Cm usermod ,
354 or
355 .Cm usershow
356 keywords on the command line without using the
357 .Fl n
358 or
359 .Fl u
360 options.
361 .El
362 .Bl -tag -width "-G grouplist"
363 .It Fl c Ar comment
364 This field sets the contents of the passwd GECOS field,
365 which normally contains up to four comma-separated fields containing the
366 user's full name, office or location,
367 and work and home phone numbers.
368 These sub-fields are used by convention only, however, and are optional.
369 If this field is to contain spaces,
370 the comment must be enclosed in double quotes
371 .Ql \&" .
372 Avoid using commas in this field as these are used as sub-field separators,
373 and the colon
374 .Ql \&:
375 character also cannot be used as this is the field separator for the passwd
376 file itself.
377 .It Fl d Ar homedir
378 This option sets the account's home directory.
379 Normally,
380 this is only used if the home directory is to be different from the
381 default determined from
382 .Pa /etc/pw.conf
383 - normally
384 .Pa /home
385 with the account name as a subdirectory.
386 .It Fl e Ar accexpdate
387 Set the account's expiration date.
388 Format of the date is either a UNIX time in decimal, or a date in
389 .Ql dd-mmm-yy[yy]
390 format, where dd is the day,
391 mmm is the month, either in numeric or alphabetic format
392 ('Jan', 'Feb', etc) and year is either a two or four digit year.
393 This option also accepts a relative date in the form
394 .Ql \&+n[mhdwoy]
395 where
396 .Ql \&n
397 is a decimal,
398 octal (leading 0) or hexadecimal (leading 0x) digit followed by the
399 number of Minutes, Hours, Days, Weeks, Months or Years from the current date at
400 which the expiration date is to be set.
401 .It Fl p Ar passexpdate
402 Set the account's password expiration date.
403 This field is similar to the account expiration date option, except that it
404 applies to forced password changes.
405 This is set in the same manner as the
406 .Fl e
407 option.
408 .It Fl g Ar group
409 Set the account's primary group to the given group.
410 .Ar group
411 may be defined by either its name or group number.
412 .It Fl G Ar grouplist
413 Set secondary group memberships for an account.
414 .Ar grouplist
415 is a comma, space, or tab-separated list of group names or group numbers.
416 The user is added to the groups specified in
417 .Ar grouplist ,
418 and removed from all groups not specified.
419 The current login session is not affected by group membership changes,
420 which only take effect when the user reconnects.
421 Note: do not add a user to their primary group with
422 .Ar grouplist .
423 .It Fl L Ar class
424 This option sets the login class for the user being created.
425 See
426 .Xr login.conf 5
427 and
428 .Xr passwd 5
429 for more information on user login classes.
430 .It Fl m
431 This option instructs
432 .Nm
433 to attempt to create the user's home directory.
434 While primarily useful when adding a new account with
435 .Cm useradd ,
436 this may also be of use when moving an existing user's home directory elsewhere
437 on the file system.
438 The new home directory is populated with the contents of the
439 .Ar skeleton
440 directory, which typically contains a set of shell configuration files that the
441 user may personalize to taste.
442 Files in this directory are usually named
443 .Pa dot . Ns Aq Ar config
444 where the
445 .Pa dot
446 prefix will be stripped.
447 When
448 .Fl m
449 is used on an account with
450 .Cm usermod ,
451 existing configuration files in the user's home directory are
452 .Em not
453 overwritten from the skeleton files.
454 .Pp
455 When a user's home directory is created,
456 it will by default be a subdirectory of the
457 .Ar basehome
458 directory as specified by the
459 .Fl b
460 option, bearing the name of the new account.
461 This can be overridden by the
462 .Fl d
463 option on the command line, if desired.
464 .It Fl M Ar mode
465 Create the user's home directory with the specified
466 .Ar mode ,
467 modified by the current
468 .Xr umask 2 .
469 If omitted, it is derived from the parent process'
470 .Xr umask 2 .
471 This option is only useful in combination with the
472 .Fl m
473 flag.
474 .It Fl k Ar skeldir
475 Set the
476 .Ar skeleton
477 directory, from which basic startup and configuration files are copied when
478 the user's home directory is created.
479 This option only has meaning when used with the
480 .Fl d
481 or
482 .Fl m
483 flags.
484 .It Fl s Ar shell
485 Set or changes the user's login shell to
486 .Ar shell .
487 If the path to the shell program is omitted,
488 .Nm
489 searches the
490 .Ar shellpath
491 specified in
492 .Pa /etc/pw.conf
493 and fills it in as appropriate.
494 Note that unless you have a specific reason to do so, you should avoid
495 specifying the path - this will allow
496 .Nm
497 to validate that the program exists and is executable.
498 Specifying a full path (or supplying a blank "" shell) avoids this check
499 and allows for such entries as
500 .Pa /nonexistent
501 that should be set for accounts not intended for interactive login.
502 .It Fl h Ar fd
503 This option provides a special interface by which interactive scripts can
504 set an account password using
505 .Nm .
506 Because the command line and environment are fundamentally insecure mechanisms
507 by which programs can accept information,
508 .Nm
509 will only allow setting of account and group passwords via a file descriptor
510 (usually a pipe between an interactive script and the program).
511 .Ar sh ,
512 .Ar bash ,
513 .Ar ksh
514 and
515 .Ar perl
516 all possess mechanisms by which this can be done.
517 Alternatively,
518 .Nm
519 will prompt for the user's password if
520 .Fl h Ar 0
521 is given, nominating
522 .Em stdin
523 as the file descriptor on which to read the password.
524 Note that this password will be read only once and is intended
525 for use by a script rather than for interactive use.
526 If you wish to have new password confirmation along the lines of
527 .Xr passwd 1 ,
528 this must be implemented as part of an interactive script that calls
529 .Nm .
530 .Pp
531 If a value of
532 .Ql \&-
533 is given as the argument
534 .Ar fd ,
535 then the password will be set to
536 .Ql \&* ,
537 rendering the account inaccessible via password-based login.
538 .It Fl H Ar fd
539 Read an encrypted password string from the specified file descriptor.
540 This is like
541 .Fl h ,
542 but the password should be supplied already encrypted in a form
543 suitable for writing directly to the password database.
544 See
545 .Xr openssl-passwd 1
546 and
547 .Xr crypt 3
548 for more details about generating an encrypted password hash.
549 .El
550 .Pp
551 It is possible to use
552 .Cm useradd
553 to create a new account that duplicates an existing user id.
554 While this is normally considered an error and will be rejected, the
555 .Fl o
556 option overrides the check for duplicates and allows the duplication of
557 the user id.
558 This may be useful if you allow the same user to login under
559 different contexts (different group allocations, different home
560 directory, different shell) while providing basically the same
561 permissions for access to the user's files in each account.
562 .Pp
563 The
564 .Cm useradd
565 command also has the ability to set new user and group defaults by using the
566 .Fl D
567 option.
568 Instead of adding a new user,
569 .Nm
570 writes a new set of defaults to its configuration file,
571 .Pa /etc/pw.conf .
572 When using the
573 .Fl D
574 option, you must not use either
575 .Fl n Ar name
576 or
577 .Fl u Ar uid
578 or an error will result.
579 Use of
580 .Fl D
581 changes the meaning of several command line switches in the
582 .Ar useradd
583 command.
584 These are:
585 .Bl -tag -width "-G grouplist"
586 .It Fl D
587 Set default values in
588 .Pa /etc/pw.conf
589 configuration file, or a different named configuration file if the
590 .Fl C Ar config
591 option is used.
592 .It Fl b Ar basehome
593 Set the root directory in which user home directories are created.
594 The default value for this is
595 .Pa /home ,
596 but it may be set elsewhere as desired.
597 .It Fl e Ar accexpdays
598 Set the default account expiration period in days.
599 When
600 .Fl D
601 is used, the
602 .Ar accexpdays
603 argument is interpreted differently.
604 It must be numeric and represents the number of days after creation
605 that the account expires.
606 A value of 0 suppresses automatic calculation of the expiry date.
607 .It Fl p Ar passexpdays
608 Set the default password expiration period in days.
609 When
610 .Fl D
611 is used, the
612 .Ar passexpdays
613 argument is interpreted differently.
614 It must be numeric and represents the number of days after creation
615 that the account expires.
616 A value of 0 suppresses automatic calculation of the expiry date.
617 .It Fl g Ar group
618 Set the default group for new users.
619 If a blank group is specified using
620 .Fl g Ar \&"" ,
621 then new users will be allocated their own private primary group
622 with the same name as their login name.
623 If a group is supplied, either its name or uid may be given as an argument.
624 .It Fl G Ar grouplist
625 Set the default groups in which new users are granted membership.
626 This is a separate set of groups from the primary group.
627 Avoid nominating the same group as both primary and extra groups.
628 In other words, these extra groups determine membership in groups
629 .Em other than
630 the primary group.
631 .Ar grouplist
632 is a comma-separated list of group names or ids, and are always
633 stored in
634 .Pa /etc/pw.conf
635 by their symbolic names.
636 .It Fl L Ar class
637 This option sets the default login class for new users.
638 .It Fl k Ar skeldir
639 Set the default
640 .Em skeleton
641 directory,
642 from which prototype shell and other initialization files are copied when
643 .Nm
644 creates a user's home directory.
645 See description of
646 .Fl k
647 for naming conventions of these files.
648 .It Xo
649 .Fl u Ar minuid Ns Cm \&, Ns Ar maxuid ,
650 .Fl i Ar mingid Ns Cm \&, Ns Ar maxgid
651 .Xc
652 Set the minimum and maximum user and group ids allocated for new
653 accounts and groups created by
654 .Nm .
655 The default values for each is 1000 minimum and 32000 maximum.
656 .Ar minuid
657 and
658 .Ar maxuid
659 are both numbers, where max must be greater than min,
660 and both must be between 0 and 32767
661 .Po the same applies to
662 .Ar mingid
663 and
664 .Ar maxgid
665 .Pc .
666 In general,
667 user and group ids less than 100 are reserved for use by the system,
668 and numbers greater than 32000 may also be reserved for special purposes
669 .Pq used by some system daemons .
670 .It Fl w Ar passmethod
671 The
672 .Fl w
673 option selects the default method used to set passwords for newly created user
674 accounts.
675 .Ar passmethod
676 is one of:
677 .Pp
678 .Bl -tag -width random -offset indent -compact
679 .It Cm no
680 disable login on newly created accounts
681 .It Cm yes
682 force the password to be the account name
683 .It Cm none
684 force a blank password
685 .It Cm random
686 generate a random password
687 .El
688 .Pp
689 The
690 .Cm random
691 or
692 .Cm no
693 methods are the most secure; in the former case,
694 .Nm
695 generates a password and prints it to stdout,
696 which is suitable when users are issued passwords rather than being allowed
697 to select their own
698 .Pq possibly poorly chosen
699 password.
700 The
701 .Cm no
702 method requires that the superuser use
703 .Xr passwd 1
704 to render the account accessible with a password.
705 .It Fl y Ar path
706 This sets the pathname of the database used by
707 .Tn NIS
708 if you are not sharing
709 the information from
710 .Pa /etc/master.passwd
711 directly with
712 .Tn NIS .
713 You should only set this option for
714 .Tn NIS
715 servers.
716 .El
717 .Pp
718 The
719 .Cm userdel
720 command has three distinct options.
721 The
722 .Fl n Ar name
723 and
724 .Fl u Ar uid
725 options have already been covered above.
726 The additional option is:
727 .Bl -tag -width "-G grouplist"
728 .It Fl r
729 This tells
730 .Nm
731 to remove the user's home directory and all of its contents.
732 The
733 .Nm
734 utility errs on the side of caution when removing files from the system.
735 Firstly,
736 it will not do so if the uid of the account being removed is also used by
737 another account on the system, and the
738 .Dq home
739 directory in the password file is
740 a valid path that commences with the character
741 .Ql \&/ .
742 Secondly, it will only remove files and directories that are actually owned by
743 the user, or symbolic links owned by anyone under the user's home directory.
744 Finally, after deleting all contents owned by the user only empty directories
745 will be removed.
746 If any additional cleanup work is required, this is left to the administrator.
747 .El
748 .Pp
749 Mail spool files and
750 .Xr crontab 5
751 files are always removed when an account is deleted as
752 these are unconditionally attached to the user name.
753 Jobs queued for processing by
754 .Xr at 1
755 are also removed if the user's uid is unique and not also used by another
756 account on the system.
757 .Pp
758 The
759 .Cm usermod
760 command adds one additional option:
761 .Bl -tag -width "-G grouplist"
762 .It Fl l Ar newname
763 This option allows changing of an existing account name to
764 .Ar newname .
765 The new name must not already exist, and any attempt to duplicate an
766 existing account name will be rejected.
767 .El
768 .Pp
769 The
770 .Cm usershow
771 command allows viewing of an account in one of two formats.
772 By default, the format is identical to the format used in
773 .Pa /etc/master.passwd
774 with the password field replaced with a
775 .Ql \&* .
776 If the
777 .Fl P
778 option is used, then
779 .Nm
780 outputs the account details in a more human readable form.
781 If the
782 .Fl 7
783 option is used, the account details are shown in v7 format.
784 The
785 .Fl a
786 option lists all users currently on file.
787 Using
788 .Fl F
789 forces
790 .Nm
791 to print the details of an account even if it does not exist.
792 .Pp
793 The command
794 .Cm usernext
795 returns the next available user and group ids separated by a colon.
796 This is normally of interest only to interactive scripts or front-ends
797 that use
798 .Nm .
799 .Sh GROUP OPTIONS
800 The
801 .Fl C
802 and
803 .Fl q
804 options (explained at the start of the previous section) are available
805 with the group manipulation commands.
806 Other common options to all group-related commands are:
807 .Bl -tag -width "-m newmembers"
808 .It Oo Fl n Oc Ar name
809 Required unless
810 .Fl g Ar gid
811 is given.
812 Specify the group name.
813 In the case of
814 .Cm groupmod
815 can be a gid.
816 .It Fl g Ar gid
817 Required if
818 .Ar name
819 is not given.
820 Specify the group numeric id.
821 In the case of
822 .Cm groupmod
823 if paired with
824 .Ar name ,
825 changes the numeric id of the named group.
826 .Pp
827 As with the account name and id fields, you will usually only need
828 to supply one of these, as the group name implies the uid and vice
829 versa.
830 You will only need to use both when setting a specific group id
831 against a new group or when changing the uid of an existing group.
832 .It Fl M Ar memberlist
833 This option provides an alternative way to add existing users to a
834 new group
835 .Pq in Cm groupadd
836 or replace an existing membership list
837 .Pq in Cm groupmod .
838 .Ar memberlist
839 is a comma separated list of valid and existing user names or uids.
840 .It Fl m Ar newmembers
841 Similar to
842 .Fl M ,
843 this option allows the
844 .Em addition
845 of existing users to a group without replacing the existing list of
846 members.
847 Login names or user ids may be used, and duplicate users are
848 silently eliminated.
849 .It Fl d Ar oldmembers
850 Similar to
851 .Fl M ,
852 this option allows the
853 .Em deletion
854 of existing users from a group without replacing the existing list of
855 members.
856 Login names or user ids may be used, and duplicate users are
857 silently eliminated.
858 .El
859 .Pp
860 .Cm groupadd
861 also has a
862 .Fl o
863 option that allows allocation of an existing group id to a new group.
864 The default action is to reject an attempt to add a group,
865 and this option overrides the check for duplicate group ids.
866 There is rarely any need to duplicate a group id.
867 .Pp
868 The
869 .Cm groupmod
870 command adds one additional option:
871 .Bl -tag -width "-m newmembers"
872 .It Fl l Ar newname
873 This option allows changing of an existing group name to
874 .Ar newname .
875 The new name must not already exist,
876 and any attempt to duplicate an existing group
877 name will be rejected.
878 .El
879 .Pp
880 Options for
881 .Cm groupshow
882 are the same as for
883 .Cm usershow ,
884 with the
885 .Fl g Ar gid
886 replacing
887 .Fl u Ar uid
888 to specify the group id.
889 The
890 .Fl 7
891 option does not apply to the
892 .Cm groupshow
893 command.
894 .Pp
895 The command
896 .Cm groupnext
897 returns the next available group id on standard output.
898 .Sh USER LOCKING
899 The
900 .Nm
901 utility
902 supports a simple password locking mechanism for users; it works by
903 prepending the string
904 .Ql *LOCKED*
905 to the beginning of the password field in
906 .Xr master.passwd 5
907 to prevent successful authentication.
908 .Pp
909 The
910 .Cm lock
911 and
912 .Cm unlock
913 commands take a user name or uid of the account to lock or unlock,
914 respectively.
915 The
916 .Fl V ,
917 .Fl C ,
918 and
919 .Fl q
920 options as described above are accepted by these commands.
921 .Sh NOTES
922 For a summary of options available with each command, you can use
923 .Dl pw [command] help
924 For example,
925 .Dl pw useradd help
926 lists all available options for the
927 .Cm useradd
928 operation.
929 .Pp
930 The
931 .Nm
932 utility allows 8-bit characters in the passwd GECOS field (user's full name,
933 office, work and home phone number subfields), but disallows them in
934 user login and group names.
935 Use 8-bit characters with caution, as connection to the Internet will
936 require that your mail transport program supports 8BITMIME, and will
937 convert headers containing 8-bit characters to 7-bit quoted-printable
938 format.
939 .Xr sendmail 8
940 does support this.
941 Use of 8-bit characters in the GECOS field should be used in
942 conjunction with the user's default locale and character set
943 and should not be implemented without their use.
944 Using 8-bit characters may also affect other
945 programs that transmit the contents of the GECOS field over the
946 Internet, such as
947 .Xr fingerd 8 ,
948 and a small number of TCP/IP clients, such as IRC, where full names
949 specified in the passwd file may be used by default.
950 .Pp
951 The
952 .Nm
953 utility writes a log to the
954 .Pa /var/log/userlog
955 file when actions such as user or group additions or deletions occur.
956 The location of this logfile can be changed in
957 .Xr pw.conf 5 .
958 .Sh FILES
959 .Bl -tag -width /etc/master.passwd.new -compact
960 .It Pa /etc/master.passwd
961 The user database
962 .It Pa /etc/passwd
963 A Version 7 format password file
964 .It Pa /etc/login.conf
965 The user capabilities database
966 .It Pa /etc/group
967 The group database
968 .It Pa /etc/pw.conf
969 Pw default options file
970 .It Pa /var/log/userlog
971 User/group modification logfile
972 .El
973 .Sh EXAMPLES
974 Add new user Glurmo Smith (gsmith).
975 A gsmith login group is created if not already present.
976 The login shell is set to
977 .Xr csh 1 .
978 A new home directory at
979 .Pa /home/gsmith
980 is created if it does not already exist.
981 Finally, a random password is generated and displayed:
982 .Bd -literal -offset indent
983 pw useradd -n gsmith -c "Glurmo Smith" -s csh -m -w random
984 .Ed
985 .Pp
986 Delete the gsmith user and their home directory, including contents.
987 .Bd -literal -offset indent
988 pw userdel -n gsmith -r
989 .Ed
990 .Pp
991 Add the existing user jsmith to the wheel group,
992 in addition to the other groups jsmith is already a member of.
993 .Bd -literal -offset indent
994 pw groupmod wheel -m jsmith
995 .Ed
996 .Pp
997 Generate random password and show it in both plain text and
998 encrypted form not modifying any database.
999 .Bd -literal -offset indent
1000 pw usermod nobody -Nw random
1001 .Ed
1002 .Sh EXIT STATUS
1003 The
1004 .Nm
1005 utility returns EXIT_SUCCESS on successful operation, otherwise
1006 .Nm
1007 returns one of the
1008 following exit codes defined by
1009 .Xr sysexits 3
1010 as follows:
1011 .Bl -tag -width xxxx
1012 .It EX_USAGE
1013 .Bl -bullet -compact
1014 .It
1015 Command line syntax errors (invalid keyword, unknown option).
1016 .El
1017 .It EX_NOPERM
1018 .Bl -bullet -compact
1019 .It
1020 Attempting to run one of the update modes as non-root.
1021 .El
1022 .It EX_OSERR
1023 .Bl -bullet -compact
1024 .It
1025 Memory allocation error.
1026 .It
1027 Read error from password file descriptor.
1028 .El
1029 .It EX_DATAERR
1030 .Bl -bullet -compact
1031 .It
1032 Bad or invalid data provided or missing on the command line or
1033 via the password file descriptor.
1034 .It
1035 Attempted to remove, rename root account or change its uid.
1036 .El
1037 .It EX_OSFILE
1038 .Bl -bullet -compact
1039 .It
1040 Skeleton directory is invalid or does not exist.
1041 .It
1042 Base home directory is invalid or does not exist.
1043 .It
1044 Invalid or non-existent shell specified.
1045 .El
1046 .It EX_NOUSER
1047 .Bl -bullet -compact
1048 .It
1049 User, user id, group or group id specified does not exist.
1050 .It
1051 User or group recorded, added, or modified unexpectedly disappeared.
1052 .El
1053 .It EX_SOFTWARE
1054 .Bl -bullet -compact
1055 .It
1056 No more group or user ids available within specified range.
1057 .El
1058 .It EX_IOERR
1059 .Bl -bullet -compact
1060 .It
1061 Unable to rewrite configuration file.
1062 .It
1063 Error updating group or user database files.
1064 .It
1065 Update error for passwd or group database files.
1066 .El
1067 .It EX_CONFIG
1068 .Bl -bullet -compact
1069 .It
1070 No base home directory configured.
1071 .El
1072 .El
1073 .Sh SEE ALSO
1074 .Xr chpass 1 ,
1075 .Xr passwd 1 ,
1076 .Xr umask 2 ,
1077 .Xr group 5 ,
1078 .Xr login.conf 5 ,
1079 .Xr passwd 5 ,
1080 .Xr pw.conf 5 ,
1081 .Xr pwd_mkdb 8 ,
1082 .Xr vipw 8
1083 .Sh HISTORY
1084 The
1085 .Nm
1086 utility was written to mimic many of the options used in the SYSV
1087 .Em shadow
1088 support suite, but is modified for passwd and group fields specific to
1089 the
1090 .Bx 4.4
1091 operating system, and combines all of the major elements
1092 into a single command.