In CentOS and Red Hat, you can set password quality requirements using the pwquality module. This module is used by the PAM (Pluggable Authentication Modules) system to enforce password quality policies. Here are the steps to set password quality requirements:
- Install the
libpwqualitypackage if it is not already installed:sudo yum install libpwquality
- Open the
pam_pwquality.conffile for editing:sudo vi /etc/security/pwquality.conf
- In the
pam_pwquality.conffile, you can set the following parameters to define the password quality requirements:minlen: The minimum length of the password (default: 9)minclass: The minimum number of character classes (default: 4)maxrepeat: The maximum number of repeated characters (default: 3)dcredit: The credit given for a digit (default: -1)ucredit: The credit given for an uppercase letter (default: -1)lcredit: The credit given for a lowercase letter (default: -1)ocredit: The credit given for a special character (default: -1)minlower: The minimum number of lowercase letters (default: 0)minupper: The minimum number of uppercase letters (default: 0)mindigit: The minimum number of digits (default: 0)minspecial: The minimum number of special characters (default: 0)
For example, to set a minimum password length of 12 and require at least one digit, one uppercase letter, one lowercase letter, and one special character, you would add the following lines to the
pam_pwquality.conffile:minlen = 12
dcredit = 1
ucredit = 1
lcredit = 1
ocredit = 1
- Save and close the
pam_pwquality.conffile. - To enforce the password quality requirements, you need to add the
pam_pwquality.somodule to the PAM configuration for the system’s password management. Open thesystem-authfile for editing:sudo vi /etc/pam.d/system-auth
- Add the following line at the top of the file:
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
This line ensures that the
pam_pwquality.somodule is used to enforce password quality requirements for local users. If you want to enforce password quality requirements for remote users as well, you need to add the line to thepassword-authfile. - Save and close the
system-authfile.
After making these changes, the PAM system will enforce the password quality requirements defined in the pam_pwquality.conf file when users change their passwords.