2 .\" David L. Nugent. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
27 .Dd September 12, 2016
32 .Nd create, remove, modify & display system users and groups
38 .Oo Fl n Oc name Oo Fl u Ar uid Oc
54 .Op Fl h Ar fd | Fl H Ar fd
72 .Op Fl u Ar min , Ns Ar max
73 .Op Fl i Ar min , Ns Ar max
81 .Oo Fl n Oc name|uid | Fl u Ar uid
88 .Oo Fl n Oc name|uid Oo Fl u Ar newuid Oc | Fl u Ar uid
104 .Op Fl h Ar fd | Fl H Ar fd
112 .Oo Fl n Oc name|uid | Fl u Ar uid
127 .Oo Fl n Oc name Oo Fl g Ar gid Oc
132 .Op Fl h Ar fd | Fl H Ar fd
140 .Oo Fl n Oc name|gid | Fl g Ar gid
146 .Oo Fl n Oc name|gid Oo Fl g Ar newgid Oc | Fl g Ar gid
151 .Op Fl m Ar newmembers
152 .Op Fl d Ar oldmembers
153 .Op Fl h Ar fd | Fl H Ar fd
161 .Oo Fl n Oc name|gid | Fl g Ar gid
175 .Oo Fl n Oc name|uid | Fl u Ar uid
182 .Oo Fl n Oc name|uid | Fl u Ar uid
188 utility is a command-line based editor for the system
192 files, allowing the superuser an easy to use and standardized way of adding,
193 modifying and removing users and groups.
196 only operates on the local user and group files.
198 users and groups must be
204 utility handles updating the
208 and the secure and insecure
209 password database files, and must be run as root.
211 The first one or two keywords provided to
213 on the command line provide the context for the remainder of the arguments.
232 all mean the same thing.)
233 This flexibility is useful for interactive scripts calling
235 for user and group database manipulation.
236 Following these keywords,
237 the user or group name or numeric id may be optionally specified as an
238 alternative to using the
244 The following flags are common to most or all modes of operation:
245 .Bl -tag -width "-G grouplist"
247 Specifies an alternate root directory within which
250 Any paths specified will be relative to
253 Set an alternate location for the password, group, and configuration files.
254 Can be used to maintain a user/group database in an alternate location.
255 If this switch is specified, the system
257 will not be sourced for default configuration data,
258 but the file pw.conf in the specified directory will be used instead
259 .Pq or none, if it does not exist .
262 flag may be used to override this behaviour.
263 As an exception to the general rule where options must follow the operation
266 flag must be used on the command line before the operation keyword.
272 to obtain policy information on how new user accounts and groups are to be created.
275 option specifies a different configuration file.
276 While most of the contents of the configuration file may be overridden via
277 command-line options, it may be more convenient to keep standard information in a
280 Use of this option causes
282 to suppress error messages,
283 which may be useful in interactive environments where it
284 is preferable to interpret status codes returned by
286 rather than messing up a carefully formatted display.
288 This option is available in
292 operations, and tells
294 to output the result of the operation without updating the user or group
298 option to switch between standard passwd and readable formats.
300 Using this option with any of the update modes causes
304 after changing to the directory
306 This is intended to allow automatic updating of
309 If separate passwd and group files are being used by
313 option to specify the location of the
315 passwd database so that
317 will concurrently update it with the system password
321 The following options apply to the
326 .Bl -tag -width "-G grouplist"
327 .It Oo Fl n Oc Ar name
331 Specify the user/account name.
339 Specify the user/account numeric id.
344 changes the numeric id of the named user/account.
346 Usually, only one of these options is required,
347 as the account name will imply the uid, or vice versa.
348 However, there are times when both are needed.
349 For example, when changing the uid of an existing user with
351 or overriding the default uid when creating a new account with
353 To automatically allocate the uid to a new user with
360 Either the account or userid can also be provided immediately after the
366 keywords on the command line without using the
372 .Bl -tag -width "-G grouplist"
374 This field sets the contents of the passwd GECOS field,
375 which normally contains up to four comma-separated fields containing the
376 user's full name, office or location,
377 and work and home phone numbers.
378 These sub-fields are used by convention only, however, and are optional.
379 If this field is to contain spaces,
380 the comment must be enclosed in double quotes
382 Avoid using commas in this field as these are used as sub-field separators,
385 character also cannot be used as this is the field separator for the passwd
388 This option sets the account's home directory.
390 this is only used if the home directory is to be different from the
391 default determined from
395 with the account name as a subdirectory.
397 Set the account's expiration date.
398 Format of the date is either a UNIX time in decimal, or a date in
400 format, where dd is the day,
401 mmm is the month, either in numeric or alphabetic format
402 ('Jan', 'Feb', etc) and year is either a two or four digit year.
403 This option also accepts a relative date in the form
408 octal (leading 0) or hexadecimal (leading 0x) digit followed by the
409 number of Minutes, Hours, Days, Weeks, Months or Years from the current date at
410 which the expiration date is to be set.
412 Set the account's password expiration date.
413 This field is similar to the account expiration date option, except that it
414 applies to forced password changes.
415 This is set in the same manner as the
419 Set the account's primary group to the given group.
421 may be defined by either its name or group number.
422 .It Fl G Ar grouplist
423 Set secondary group memberships for an account.
425 is a comma, space, or tab-separated list of group names or group numbers.
426 The user is added to the groups specified in
428 and removed from all groups not specified.
429 The current login session is not affected by group membership changes,
430 which only take effect when the user reconnects.
431 Note: do not add a user to their primary group with
434 This option sets the login class for the user being created.
439 for more information on user login classes.
441 This option instructs
443 to attempt to create the user's home directory.
444 While primarily useful when adding a new account with
446 this may also be of use when moving an existing user's home directory elsewhere
448 The new home directory is populated with the contents of the
450 directory, which typically contains a set of shell configuration files that the
451 user may personalize to taste.
452 Files in this directory are usually named
453 .Pa dot . Ns Aq Ar config
456 prefix will be stripped.
459 is used on an account with
461 existing configuration files in the user's home directory are
463 overwritten from the skeleton files.
465 When a user's home directory is created,
466 it will by default be a subdirectory of the
468 directory as specified by the
470 option (see below), bearing the name of the new account.
471 This can be overridden by the
473 option on the command line, if desired.
475 Create the user's home directory with the specified
477 modified by the current
479 If omitted, it is derived from the parent process'
481 This option is only useful in combination with the
487 directory, from which basic startup and configuration files are copied when
488 the user's home directory is created.
489 This option only has meaning when used with the
495 Set or changes the user's login shell to
497 If the path to the shell program is omitted,
503 and fills it in as appropriate.
504 Note that unless you have a specific reason to do so, you should avoid
505 specifying the path - this will allow
507 to validate that the program exists and is executable.
508 Specifying a full path (or supplying a blank "" shell) avoids this check
509 and allows for such entries as
511 that should be set for accounts not intended for interactive login.
513 This option provides a special interface by which interactive scripts can
514 set an account password using
516 Because the command line and environment are fundamentally insecure mechanisms
517 by which programs can accept information,
519 will only allow setting of account and group passwords via a file descriptor
520 (usually a pipe between an interactive script and the program).
526 all possess mechanisms by which this can be done.
529 will prompt for the user's password if
533 as the file descriptor on which to read the password.
534 Note that this password will be read only once and is intended
535 for use by a script rather than for interactive use.
536 If you wish to have new password confirmation along the lines of
538 this must be implemented as part of an interactive script that calls
543 is given as the argument
545 then the password will be set to
547 rendering the account inaccessible via password-based login.
549 Read an encrypted password string from the specified file descriptor.
552 but the password should be supplied already encrypted in a form
553 suitable for writing directly to the password database.
556 It is possible to use
558 to create a new account that duplicates an existing user id.
559 While this is normally considered an error and will be rejected, the
561 option overrides the check for duplicates and allows the duplication of
563 This may be useful if you allow the same user to login under
564 different contexts (different group allocations, different home
565 directory, different shell) while providing basically the same
566 permissions for access to the user's files in each account.
570 command also has the ability to set new user and group defaults by using the
573 Instead of adding a new user,
575 writes a new set of defaults to its configuration file,
579 option, you must not use either
583 or an error will result.
586 changes the meaning of several command line switches in the
590 .Bl -tag -width "-G grouplist"
592 Set default values in
594 configuration file, or a different named configuration file if the
598 Set the root directory in which user home directories are created.
599 The default value for this is
601 but it may be set elsewhere as desired.
603 Set the default account expiration period in days.
608 argument is interpreted differently.
609 It must be numeric and represents the number of days after creation
610 that the account expires.
611 A value of 0 suppresses automatic calculation of the expiry date.
613 Set the default password expiration period in days.
615 Set the default group for new users.
616 If a blank group is specified using
618 then new users will be allocated their own private primary group
619 with the same name as their login name.
620 If a group is supplied, either its name or uid may be given as an argument.
621 .It Fl G Ar grouplist
622 Set the default groups in which new users are granted membership.
623 This is a separate set of groups from the primary group.
624 Avoid nominating the same group as both primary and extra groups.
625 In other words, these extra groups determine membership in groups
629 is a comma-separated list of group names or ids, and are always
632 by their symbolic names.
634 This option sets the default login class for new users.
639 from which prototype shell and other initialization files are copied when
641 creates a user's home directory.
644 for naming conventions of these files.
646 .Fl u Ar min , Ns Ar max ,
647 .Fl i Ar min , Ns Ar max
649 Set the minimum and maximum user and group ids allocated for new
650 accounts and groups created by
652 The default values for each is 1000 minimum and 32000 maximum.
656 are both numbers, where max must be greater than min,
657 and both must be between 0 and 32767.
659 user and group ids less than 100 are reserved for use by the system,
660 and numbers greater than 32000 may also be reserved for special purposes
661 .Pq used by some system daemons .
665 option selects the default method used to set passwords for newly created user
670 .Bl -tag -width random -offset indent -compact
672 disable login on newly created accounts
674 force the password to be the account name
676 force a blank password
678 generate a random password
685 methods are the most secure; in the former case,
687 generates a password and prints it to stdout,
688 which is suitable when users are issued passwords rather than being allowed
690 .Pq possibly poorly chosen
694 method requires that the superuser use
696 to render the account accessible with a password.
698 This sets the pathname of the database used by
700 if you are not sharing
702 .Pa /etc/master.passwd
705 You should only set this option for
712 command has three distinct options.
717 options have already been covered above.
718 The additional option is:
719 .Bl -tag -width "-G grouplist"
723 to remove the user's home directory and all of its contents.
726 utility errs on the side of caution when removing files from the system.
728 it will not do so if the uid of the account being removed is also used by
729 another account on the system, and the 'home' directory in the password file is
730 a valid path that commences with the character
732 Secondly, it will only remove files and directories that are actually owned by
733 the user, or symbolic links owned by anyone under the user's home directory.
734 Finally, after deleting all contents owned by the user only empty directories
736 If any additional cleanup work is required, this is left to the administrator.
739 Mail spool files and crontabs are always removed when an account is deleted as
740 these are unconditionally attached to the user name.
741 Jobs queued for processing by
743 are also removed if the user's uid is unique and not also used by another
744 account on the system.
748 command adds one additional option:
749 .Bl -tag -width "-G grouplist"
751 This option allows changing of an existing account name to
753 The new name must not already exist, and any attempt to duplicate an
754 existing account name will be rejected.
759 command allows viewing of an account in one of two formats.
760 By default, the format is identical to the format used in
761 .Pa /etc/master.passwd
762 with the password field replaced with a
768 outputs the account details in a more human readable form.
771 option is used, the account details are shown in v7 format.
774 option lists all users currently on file.
779 to print the details of an account even if it does not exist.
783 returns the next available user and group ids separated by a colon.
784 This is normally of interest only to interactive scripts or front-ends
792 options (explained at the start of the previous section) are available
793 with the group manipulation commands.
794 Other common options to all group-related commands are:
795 .Bl -tag -width "-m newmembers"
796 .It Oo Fl n Oc Ar name
800 Specify the group name.
808 Specify the group numeric id.
813 changes the numeric id of the named group.
815 As with the account name and id fields, you will usually only need
816 to supply one of these, as the group name implies the uid and vice
818 You will only need to use both when setting a specific group id
819 against a new group or when changing the uid of an existing group.
820 .It Fl M Ar memberlist
821 This option provides an alternative way to add existing users to a
822 new group (in groupadd) or replace an existing membership list (in
825 is a comma separated list of valid and existing user names or uids.
826 .It Fl m Ar newmembers
829 this option allows the
831 of existing users to a group without replacing the existing list of
833 Login names or user ids may be used, and duplicate users are
835 .It Fl d Ar oldmembers
838 this option allows the
840 of existing users from a group without replacing the existing list of
842 Login names or user ids may be used, and duplicate users are
849 option that allows allocation of an existing group id to a new group.
850 The default action is to reject an attempt to add a group,
851 and this option overrides the check for duplicate group ids.
852 There is rarely any need to duplicate a group id.
856 command adds one additional option:
857 .Bl -tag -width "-m newmembers"
859 This option allows changing of an existing group name to
861 The new name must not already exist,
862 and any attempt to duplicate an existing group
863 name will be rejected.
874 to specify the group id.
877 option does not apply to the
883 returns the next available group id on standard output.
888 supports a simple password locking mechanism for users; it works by
889 prepending the string
891 to the beginning of the password field in
893 to prevent successful authentication.
899 commands take a user name or uid of the account to lock or unlock,
906 options as described above are accepted by these commands.
908 For a summary of options available with each command, you can use
909 .Dl pw [command] help
912 lists all available options for the useradd operation.
916 utility allows 8-bit characters in the passwd GECOS field (user's full name,
917 office, work and home phone number subfields), but disallows them in
918 user login and group names.
919 Use 8-bit characters with caution, as connection to the Internet will
920 require that your mail transport program supports 8BITMIME, and will
921 convert headers containing 8-bit characters to 7-bit quoted-printable
925 Use of 8-bit characters in the GECOS field should be used in
926 conjunction with the user's default locale and character set
927 and should not be implemented without their use.
928 Using 8-bit characters may also affect other
929 programs that transmit the contents of the GECOS field over the
932 and a small number of TCP/IP clients, such as IRC, where full names
933 specified in the passwd file may be used by default.
937 utility writes a log to the
939 file when actions such as user or group additions or deletions occur.
940 The location of this logfile can be changed in
943 .Bl -tag -width /etc/master.passwd.new -compact
944 .It Pa /etc/master.passwd
947 A Version 7 format password file
948 .It Pa /etc/login.conf
949 The user capabilities database
953 Pw default options file
954 .It Pa /var/log/userlog
955 User/group modification logfile
958 Add new user Glurmo Smith (gsmith).
959 A gsmith login group is created if not already present.
960 The login shell is set to
962 A new home directory at
964 is created if it does not already exist.
965 Finally, a random password is generated and displayed:
966 .Bd -literal -offset indent
967 pw useradd -n gsmith -c "Glurmo Smith" -s /bin/csh -m -w random
970 Delete the gsmith user and their home directory, including contents.
971 .Bd -literal -offset indent
972 pw userdel -n gsmith -r
977 utility returns EXIT_SUCCESS on successful operation, otherwise
980 following exit codes defined by
987 Command line syntax errors (invalid keyword, unknown option).
992 Attempting to run one of the update modes as non-root.
997 Memory allocation error.
999 Read error from password file descriptor.
1002 .Bl -bullet -compact
1004 Bad or invalid data provided or missing on the command line or
1005 via the password file descriptor.
1007 Attempted to remove, rename root account or change its uid.
1010 .Bl -bullet -compact
1012 Skeleton directory is invalid or does not exist.
1014 Base home directory is invalid or does not exist.
1016 Invalid or non-existent shell specified.
1019 .Bl -bullet -compact
1021 User, user id, group or group id specified does not exist.
1023 User or group recorded, added, or modified unexpectedly disappeared.
1026 .Bl -bullet -compact
1028 No more group or user ids available within specified range.
1031 .Bl -bullet -compact
1033 Unable to rewrite configuration file.
1035 Error updating group or user database files.
1037 Update error for passwd or group database files.
1040 .Bl -bullet -compact
1042 No base home directory configured.
1058 utility was written to mimic many of the options used in the SYSV
1060 support suite, but is modified for passwd and group fields specific to
1063 operating system, and combines all of the major elements
1064 into a single command.