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 February 11, 2026 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 uniqueness and allows the duplication of 576the uid. 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 . 689Also, uids and gids between 100 and 999 are commonly used by pseudo-users 690associated with third-party programs, and generally should be avoided for 691assigning for normal users. 692.It Fl w Ar passmethod 693The 694.Fl w 695option selects the default method used to set passwords for newly created user 696accounts. 697.Ar passmethod 698is one of: 699.Pp 700.Bl -tag -width random -offset indent -compact 701.It Cm no 702disable login on newly created accounts 703.It Cm yes 704force the password to be the account name 705.It Cm none 706force a blank password 707.It Cm random 708generate a random password 709.El 710.Pp 711The 712.Cm random 713or 714.Cm no 715methods are the most secure; in the former case, 716.Nm 717generates a password and prints it to stdout, 718which is suitable when users are issued passwords rather than being allowed 719to select their own 720.Pq possibly poorly chosen 721password. 722The 723.Cm no 724method requires that the superuser use 725.Xr passwd 1 726to render the account accessible with a password. 727.It Fl y Ar path 728This sets the pathname of the database used by 729.Tn NIS 730if you are not sharing 731the information from 732.Pa /etc/master.passwd 733directly with 734.Tn NIS . 735You should only set this option for 736.Tn NIS 737servers. 738.El 739.Pp 740The 741.Cm userdel 742command has three distinct options. 743The 744.Fl n Ar name 745and 746.Fl u Ar uid 747options have already been covered above. 748The additional option is: 749.Bl -tag -width "-G grouplist" 750.It Fl r 751This tells 752.Nm 753to remove the user's home directory and all of its contents. 754The 755.Nm 756utility errs on the side of caution when removing files from the system. 757Firstly, 758it will not do so if the uid of the account being removed is also used by 759another account on the system, and the 760.Dq home 761directory in the password file is 762a valid path that commences with the character 763.Ql \&/ . 764Secondly, it will only remove files and directories that are actually owned by 765the user, or symbolic links owned by anyone under the user's home directory. 766Finally, after deleting all contents owned by the user only empty directories 767will be removed. 768If the home directory is a ZFS dataset and has been emptied, 769the dataset will be destroyed. 770ZFS datasets within the home directory and snapshots are not handled. 771If any additional cleanup work is required, this is left to the administrator. 772.El 773.Pp 774Mail spool files and 775.Xr crontab 5 776files are always removed when an account is deleted as 777these are unconditionally attached to the user name. 778Jobs queued for processing by 779.Xr at 1 780are also removed if the user's uid is unique and not also used by another 781account on the system. 782.Pp 783The 784.Cm usermod 785command adds one additional option: 786.Bl -tag -width "-G grouplist" 787.It Fl l Ar newname 788This option allows changing of an existing account name to 789.Ar newname . 790The new name must not already exist, and any attempt to duplicate an 791existing account name will be rejected. 792.El 793.Pp 794The 795.Cm usershow 796command allows viewing of an account in one of two formats. 797By default, the format is identical to the format used in 798.Pa /etc/master.passwd 799with the password field replaced with a 800.Ql \&* . 801If the 802.Fl P 803option is used, then 804.Nm 805outputs the account details in a more human readable form. 806If the 807.Fl 7 808option is used, the account details are shown in v7 format. 809The 810.Fl a 811option lists all users currently on file. 812Using 813.Fl F 814forces 815.Nm 816to print the details of an account even if it does not exist. 817.Pp 818The command 819.Cm usernext 820returns the next available user and group ids separated by a colon. 821This is normally of interest only to interactive scripts or front-ends 822that use 823.Nm . 824.Sh GROUP OPTIONS 825The 826.Fl C 827and 828.Fl q 829options (explained at the start of the previous section) are available 830with the group manipulation commands. 831Other common options to all group-related commands are: 832.Bl -tag -width "-m newmembers" 833.It Oo Fl n Oc Ar name 834Required unless 835.Fl g Ar gid 836is given. 837Specify the group name. 838In the case of 839.Cm groupmod 840can be a gid. 841.It Fl g Ar gid 842Required if 843.Ar name 844is not given. 845Specify the group numeric id. 846In the case of 847.Cm groupmod 848if paired with 849.Ar name , 850changes the numeric id of the named group. 851.Pp 852As with the account name and id fields, you will usually only need 853to supply one of these, as the group name implies the uid and vice 854versa. 855You will only need to use both when setting a specific group id 856against a new group or when changing the uid of an existing group. 857.It Fl M Ar memberlist 858This option provides an alternative way to add existing users to a 859new group 860.Pq in Cm groupadd 861or replace an existing membership list 862.Pq in Cm groupmod . 863.Ar memberlist 864is a comma, space, or tab-separated list of valid and existing user names or 865uids. 866.It Fl m Ar newmembers 867Similar to 868.Fl M , 869this option allows the 870.Em addition 871of existing users to a group without replacing the existing list of 872members. 873Login names or user ids may be used, and duplicate users are 874silently eliminated. 875.It Fl d Ar oldmembers 876Similar to 877.Fl M , 878this option allows the 879.Em deletion 880of existing users from a group without replacing the existing list of 881members. 882Login names or user ids may be used, and duplicate users are 883silently eliminated. 884.El 885.Pp 886.Cm groupadd 887also has a 888.Fl o 889option that allows allocation of an existing group id to a new group. 890The default action is to reject an attempt to add a group, 891and this option overrides the check for duplicate group ids. 892There is rarely any need to duplicate a gid. 893.Pp 894The 895.Cm groupmod 896command adds one additional option: 897.Bl -tag -width "-m newmembers" 898.It Fl l Ar newname 899This option allows changing of an existing group name to 900.Ar newname . 901The new name must not already exist, 902and any attempt to duplicate an existing group 903name will be rejected. 904.El 905.Pp 906Options for 907.Cm groupshow 908are the same as for 909.Cm usershow , 910with the 911.Fl g Ar gid 912replacing 913.Fl u Ar uid 914to specify the group id. 915The 916.Fl 7 917option does not apply to the 918.Cm groupshow 919command. 920.Pp 921The command 922.Cm groupnext 923returns the next available group id on standard output. 924.Sh USER LOCKING 925The 926.Nm 927utility 928supports a simple password locking mechanism for users; it works by 929prepending the string 930.Ql *LOCKED* 931to the beginning of the password field in 932.Xr master.passwd 5 933to prevent successful authentication. 934.Pp 935The 936.Cm lock 937and 938.Cm unlock 939commands take a user name or uid of the account to lock or unlock, 940respectively. 941The 942.Fl V , 943.Fl C , 944and 945.Fl q 946options as described above are accepted by these commands. 947.Sh NOTES 948For a summary of options available with each command, you can use 949.Dl pw [command] help 950For example, 951.Dl pw useradd help 952lists all available options for the 953.Cm useradd 954operation. 955.Pp 956The 957.Nm 958utility allows 8-bit characters in the passwd GECOS field (user's full name, 959office, work and home phone number subfields), but disallows them in 960user login and group names. 961Use 8-bit characters with caution, as connection to the Internet will 962require that your mail transport program supports 8BITMIME, and will 963convert headers containing 8-bit characters to 7-bit quoted-printable 964format. 965.Xr sendmail 8 966does support this. 967Use of 8-bit characters in the GECOS field should be used in 968conjunction with the user's default locale and character set 969and should not be implemented without their use. 970Using 8-bit characters may also affect other 971programs that transmit the contents of the GECOS field over the 972Internet, such as 973.Xr fingerd 8 , 974and a small number of TCP/IP clients, such as IRC, where full names 975specified in the passwd file may be used by default. 976.Pp 977The 978.Nm 979utility writes a log to the 980.Pa /var/log/userlog 981file when actions such as user or group additions or deletions occur. 982The location of this logfile can be changed in 983.Xr pw.conf 5 . 984.Sh FILES 985.Bl -tag -width /etc/master.passwd.new -compact 986.It Pa /etc/master.passwd 987The user database 988.It Pa /etc/passwd 989A Version 7 format password file 990.It Pa /etc/login.conf 991The user capabilities database 992.It Pa /etc/group 993The group database 994.It Pa /etc/pw.conf 995Pw default options file 996.It Pa /var/log/userlog 997User/group modification logfile 998.El 999.Sh EXAMPLES 1000Add new user Glurmo Smith (gsmith). 1001A gsmith login group is created if not already present. 1002The login shell is set to 1003.Xr csh 1 . 1004A new home directory at 1005.Pa /home/gsmith 1006is created if it does not already exist. 1007Finally, a random password is generated and displayed: 1008.Bd -literal -offset indent 1009pw useradd -n gsmith -c "Glurmo Smith" -s csh -m -w random 1010.Ed 1011.Pp 1012Delete the gsmith user and their home directory, including contents. 1013.Bd -literal -offset indent 1014pw userdel -n gsmith -r 1015.Ed 1016.Pp 1017Add the existing user jsmith to the wheel group, 1018in addition to the other groups jsmith is already a member of. 1019.Bd -literal -offset indent 1020pw groupmod wheel -m jsmith 1021.Ed 1022.Pp 1023Generate random password and show it in both plain text and 1024encrypted form not modifying any database. 1025.Bd -literal -offset indent 1026pw usermod nobody -Nw random 1027.Ed 1028.Sh EXIT STATUS 1029The 1030.Nm 1031utility returns EXIT_SUCCESS on successful operation, otherwise 1032.Nm 1033returns one of the 1034following exit codes defined by 1035.Xr sysexits 3 1036as follows: 1037.Bl -tag -width xxxx 1038.It EX_USAGE 1039.Bl -bullet -compact 1040.It 1041Command line syntax errors (invalid keyword, unknown option). 1042.El 1043.It EX_NOPERM 1044.Bl -bullet -compact 1045.It 1046Attempting to run one of the update modes as non-root. 1047.El 1048.It EX_OSERR 1049.Bl -bullet -compact 1050.It 1051Memory allocation error. 1052.It 1053Read error from password file descriptor. 1054.El 1055.It EX_DATAERR 1056.Bl -bullet -compact 1057.It 1058Bad or invalid data provided or missing on the command line or 1059via the password file descriptor. 1060.It 1061Attempted to remove, rename root account or change its uid. 1062.El 1063.It EX_OSFILE 1064.Bl -bullet -compact 1065.It 1066Skeleton directory is invalid or does not exist. 1067.It 1068Base home directory is invalid or does not exist. 1069.It 1070Invalid or non-existent shell specified. 1071.El 1072.It EX_NOUSER 1073.Bl -bullet -compact 1074.It 1075User, user id, group or group id specified does not exist. 1076.It 1077User or group recorded, added, or modified unexpectedly disappeared. 1078.El 1079.It EX_SOFTWARE 1080.Bl -bullet -compact 1081.It 1082No more group or user ids available within specified range. 1083.El 1084.It EX_IOERR 1085.Bl -bullet -compact 1086.It 1087Unable to rewrite configuration file. 1088.It 1089Error updating group or user database files. 1090.It 1091Update error for passwd or group database files. 1092.El 1093.It EX_CONFIG 1094.Bl -bullet -compact 1095.It 1096No base home directory configured. 1097.El 1098.El 1099.Sh SEE ALSO 1100.Xr chpass 1 , 1101.Xr passwd 1 , 1102.Xr umask 2 , 1103.Xr group 5 , 1104.Xr login.conf 5 , 1105.Xr passwd 5 , 1106.Xr pw.conf 5 , 1107.Xr pwd_mkdb 8 , 1108.Xr vipw 8 , 1109.Xr zfs 8 1110.Sh HISTORY 1111The 1112.Nm 1113utility was written to mimic many of the options used in the SYSV 1114.Em shadow 1115support suite, but is modified for passwd and group fields specific to 1116the 1117.Bx 4.4 1118operating system, and combines all of the major elements 1119into a single command. 1120