PAM_PWQUALITY(8)

๐Ÿ“ฆ
version 1.4.5 ยท 5 versions
, in alpine 3.24, debian bookworm, debian trixie, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– PAM_PWQUALITY โ€” the pam_pwquality manual, bestie edition ๐Ÿ’–

okay so we're doing PAM_PWQUALITY(8) from the Linux-PAM Manual today, and honestly? this one's a baddie. it's the module that looks at your password and goes "girl... no." โœจ


โœจ NAME โœจ

pam_pwquality โ€” a PAM module that does password quality checking ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

pam_pwquality.so [...]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So here's the vibe: you can plug this module into the password stack of any service, and it'll do some plug-in strength-checking on passwords for you. The code was originally based on the pam_cracklib module, and it's backwards compatible with all of that module's options. iconic behavior, honestly. ๐Ÿ‘‘

What this module actually does is prompt the user for a password and then check how strong it is against a system dictionary plus a whole set of rules for spotting bad choices. it's giving personal trainer but for your password.

The first move is to prompt for a single password, check its strength, and then โ€” only if it's considered strong โ€” prompt for the password a second time, to verify you typed it right the first time. If all goes well, the password gets passed along to the subsequent modules so it can be installed as the new authentication token. slay.

Here are the checks it runs:

  • Palindrome โ€” is the new password a palindrome? ๐Ÿ™ƒ
  • Case Change Only โ€” is the new password literally the same as the old one, just with the case changed?
  • Similar โ€” is the new password too much like the old one? This one is primarily controlled by a single argument, difok, which is the number of character changes (inserts, removals, or replacements) between the old and new password that are enough to accept the new password.
  • Simple โ€” is the new password too small? This is controlled by 6 arguments: minlen, maxclassrepeat, dcredit, ucredit, lcredit, and ocredit. Head to the arguments section for the deets on how these work and what their defaults are.
  • Rotated โ€” is the new password a rotated version of the old password?
  • Same consecutive characters โ€” optional check for same consecutive characters.
  • Too long monotonic character sequence โ€” optional check for too long monotonic character sequence.
  • Contains user name โ€” checks whether the password contains the user's name in some form.
  • Dictionary check โ€” the Cracklib routine gets called to check if the password is part of a dictionary. ๐Ÿ“–

All of these checks are configurable either by using the module arguments or by editing the /etc/security/pwquality.conf configuration file. And important: the module arguments override the settings in the configuration file. periodt.


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • debug โ€” makes the module write information to syslog(3) about what it's doing. (and no, this option does not write password information to the log file. privacy queen. ๐Ÿ™ˆ)
  • authtok_type=XXX โ€” the default action is for the module to use these prompts when requesting passwords: "New UNIX password: " and "Retype UNIX password: ". The example word UNIX can be replaced with this option โ€” by default it's empty.
  • retry=N โ€” prompt the user at most N times before returning with an error. The default is 1.
  • difok=N โ€” this argument changes the default of 1 for the number of changes in the new password from the old password.
    • The special value of 0 disables all checks of similarity of the new password with the old password โ€” except for the new password being exactly the same as the old one. ๐Ÿ˜ฌ
  • minlen=N โ€” the minimum acceptable size for the new password (plus one if credits are not disabled, which is the default). On top of the number of characters in the new password, you get credit (of +1 in length) for each different kind of character (other, upper, lower and digit). The default for this parameter is 8. Note that there's also a pair of length limits in Cracklib, which is used for dictionary checking: a "way too short" limit of 4 which is hard coded in, and a build time defined limit (6) that will be checked without reference to minlen.
  • dcredit=N
    • (N >= 0) this is the maximum credit for having digits in the new password. If you have less than or N digits, each digit will count +1 towards meeting the current minlen value. The default for dcredit is 0, which means there's no bonus for digits in the password.
    • (N < 0) this is the minimum number of digits that must be met for a new password.
  • ucredit=N
    • (N >= 0) this is the maximum credit for having upper case letters in the new password. If you have less than or N upper case letters, each upper case letter will count +1 towards meeting the current minlen value. The default for ucredit is 0, which means there's no bonus for upper case letters in the password.
    • (N < 0) this is the minimum number of upper case letters that must be met for a new password.
  • lcredit=N
    • (N >= 0) this is the maximum credit for having lower case letters in the new password. If you have less than or N lower case letters, each lower case letter will count +1 towards meeting the current minlen value. The default for lcredit is 0, which means there's no bonus for lower case letters in the password.
    • (N < 0) this is the minimum number of lower case letters that must be met for a new password.
  • ocredit=N
    • (N >= 0) this is the maximum credit for having other characters in the new password. If you have less than or N other characters, each other character will count +1 towards meeting the current minlen value. The default for ocredit is 0, which means there's no bonus for other characters in the password.
    • (N < 0) this is the minimum number of other characters that must be met for a new password.
  • minclass=N โ€” the minimum number of required classes of characters for the new password. The four classes are digits, upper and lower letters, and other characters. The difference from the credit check is that a specific class of characters is not required โ€” instead, N out of the four classes are required. By default the check is disabled.
  • maxrepeat=N โ€” reject passwords that contain more than N same consecutive characters. The default is 0, which means this check is disabled.
  • maxsequence=N โ€” reject passwords that contain monotonic character sequences longer than N. The default is 0, which means this check is disabled. Examples of such a sequence are '12345' or 'fedcb'. Note that most such passwords will not pass the simplicity check unless the sequence is only a minor part of the password.
  • maxclassrepeat=N โ€” reject passwords that contain more than N consecutive characters of the same class. The default is 0, which means this check is disabled.
  • gecoscheck=N โ€” if nonzero, check whether the individual words longer than 3 characters from the passwd(5) GECOS field of the user are contained in the new password. The default is 0, which means this check is disabled.
  • dictcheck=N โ€” if nonzero, check whether the password (with possible modifications) matches a word in a dictionary. Currently the dictionary check is performed using the cracklib library. The default is 1, which means this check is enabled. โœ…
  • usercheck=N โ€” if nonzero, check whether the password (with possible modifications) contains the user name in some form. The default is 1, which means this check is enabled. It is not performed for user names shorter than 3 characters.
  • usersubstr=N โ€” if greater than 3 (due to the minimum length in usercheck), check whether the password contains a substring of the user name of at least N length in some form. The default is 0, which means this check is disabled.
  • enforcing=N โ€” if nonzero, reject the password if it fails the checks; otherwise it only prints the warning. The default is 1, which means the weak password is rejected (for non-root users).
  • badwords=<list of words> โ€” the words more than 3 characters long from this space separated list are individually searched for and forbidden in the new password. By default the list is empty, which means this check is disabled. ๐Ÿšซ
  • dictpath=/path/to/dict โ€” this option allows you to specify a non-default path to the cracklib dictionaries.
  • enforce_for_root โ€” the module will return an error on a failed check even if the user changing the password is root. This option is off by default, which means that just the message about the failed check is printed, but root can change the password anyway. Note that root is not asked for an old password, so the checks that compare the old and new password are not performed. ๐Ÿ‘‘
  • local_users_only โ€” the module will not test the password quality for users that are not present in the /etc/passwd file. The module still asks for the password so the following modules in the stack can use the use_authtok option. This option is off by default.
  • use_authtok โ€” this argument is used to force the module to not prompt the user for a new password, but instead use the one provided by the previously stacked password module.

๐ŸŒˆ MODULE TYPES PROVIDED ๐ŸŒˆ

Only the password module type is provided. that's it, that's the whole list. ๐Ÿ’…


โญ RETURN VALUES โญ

  • PAM_SUCCESS โ€” the new password passes all checks. yay!! ๐ŸŽ‰
  • PAM_AUTHTOK_ERR โ€” no new password was entered, the username could not be determined, or the new password fails the strength checks.
  • PAM_AUTHTOK_RECOVERY_ERR โ€” the old password was not supplied by a previous stacked module, or it got not requested from the user. The first error can happen if use_authtok is specified.
  • PAM_SERVICE_ERR โ€” an internal error occurred. ๐Ÿ’€

okay wait, there's still more of this page coming โ€” don't go anywhere bestie, part 2 is right behind this ๐Ÿซถ

๐Ÿ’ซ EXAMPLES ๐Ÿ’ซ

okay bestie, real talk, this is the part where it all comes together โœจ lemme show you how this module gets stacked with the password component of pam_unix(8).

First one up โ€” and listen, this is the classic:

#
# These lines stack two password type modules. In this example the
# user is given 3 opportunities to enter a strong password. The
# "use_authtok" argument ensures that the pam_unix module does not
# prompt for a password, but instead uses the one provided by
# pam_pwquality.
#
password required pam_pwquality.so retry=3
password required pam_unix.so use_authtok

so basically you got two password type modules stacked like the iconic duo they are, and the user gets 3 chances to come up with a strong password. and the use_authtok argument? that's the MVP ๐Ÿซถ it makes sure the pam_unix module does NOT prompt for a password โ€” it just takes the one pam_pwquality already got. no double-prompting, no chaos, no drama ๐Ÿ’…


next scenario: you want that sha256 password encryption, bestie, so let's go ๐Ÿ‘‘

#
# These lines allow modern systems to support passwords of at least 14
# bytes with extra credit of 2 for digits and 2 for others the new
# password must have at least three bytes that are not present in the
# old password
#
password required pam_pwquality.so \
              difok=3 minlen=15 dcredit=2 ocredit=2
password required pam_unix.so use_authtok nullok sha256

okay so what's happening here: modern systems get to support passwords of at least 14 bytes ๐Ÿฆ‹, plus extra credit of 2 for digits and 2 for others, and the new password has to have at least three bytes that are not present in the old password (difok=3). it's giving โœจthoroughโœจ ngl.


and last one, the "we're not doing credits today" edition ๐Ÿ™ˆ

#
# These lines require the user to select a password with a minimum
# length of 8 and with at least 1 digit number, 1 upper case letter,
# and 1 other character
#
password required pam_pwquality.so \
              dcredit=-1 ucredit=-1 ocredit=-1 lcredit=0 minlen=8
password required pam_unix.so use_authtok nullok sha256

here the user has to pick a password with a minimum length of 8, plus at least 1 digit number, 1 upper case letter, and 1 other character. note how the credits are negative (dcredit=-1 ucredit=-1 ocredit=-1) โ€” that's the "you must have at least this many" mode, while lcredit=0 is just chilling ๐Ÿ˜Œ periodt.


๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

go read those too, they're the supporting cast and honestly? they ate ๐Ÿ’–


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

  • Tomas Mraz <tmraz@redhat.com>
  • Original author of the pam_cracklib module, Cristian Gafton <gafton@redhat.com>

and that's a wrap bestie!! ๐ŸŒธ this whole page comes to you from Red Hat, Inc., dated 2022-11-18, and it's PAM_PWQUALITY(8) โ€” the password quality icon it was always meant to be ๐Ÿ’…โœจ no cap, go forth and set your minlen responsibly ๐Ÿซถ๐ŸŒˆ

๐Ÿ“ฆ where this page comes from