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