OpenBSD manual page server

Manual Page Search Parameters

PWD_MKDB(8) System Manager's Manual PWD_MKDB(8)

pwd_mkdbgenerate the password databases

pwd_mkdb [-c] [-p | -s] [-d directory] [-u username] file

pwd_mkdb creates a pair of Berkeley databases from file and installs them into /etc/spwd.db and /etc/pwd.db. The file argument is renamed to /etc/master.passwd.

The options are as follows:

Check whether file is in the correct format. Do not change, add, or remove any files.
directory
Operate in a base directory other than the default of /etc. All absolute paths (including file) will be made relative to directory. Any directories specified as a part of file will be stripped off. This option is used to create password databases in directories other than /etc; for instance in a chroot(8) jail.
Also create a legacy password file and install it into /etc/passwd.
Only update the secure version of the database. This is most commonly used in conjunction with the -u flag during a password change. Because the insecure database doesn't contain the password there is no reason to update it if the only change is in the password field. Cannot be used in conjunction with the -p flag.
username
Only update the record for the specified user. Utilities that operate on a single user can use this option to avoid the overhead of rebuilding the entire database. This option must never be used if the line number of the user's record in /etc/master.passwd has changed.
file
The absolute path to a file in master.passwd(5) format.

The two databases differ in that the secure version contains the user's encrypted password and the insecure version has an asterisk (‘*’).

The databases are used by the C library password routines (see getpwent(3)).

/etc/master.passwd
current password file
/etc/passwd
legacy password file
/etc/pwd.db
insecure password database file
/etc/pwd.db.tmp
temporary file
/etc/spwd.db
secure password database file
/etc/spwd.db.tmp
temporary file

The pwd_mkdb utility exits 0 on success, and >0 if an error occurs.

chpass(1), passwd(1), dbopen(3), getpwent(3), passwd(5), vipw(8)

The pwd_mkdb utility first appeared in 4.3BSD-Net/2.

Keith Bostic

Because of the necessity for atomic update of the password files, pwd_mkdb uses rename(2) to install them. This, however, requires that the file specified on the command line live on the same file system as the /etc directory.

There are the obvious races with multiple people running pwd_mkdb on different password files at the same time. The front-ends to pwd_mkdb, chpass(1), passwd(1), and vipw(8) handle the locking necessary to avoid this problem.

September 10, 2017 OpenBSD-6.6