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