Enforcing Password Complexity
After configuring the password complexity settings in Linux, the next step is to enforce these policies to ensure that users adhere to the established security requirements. There are several ways to enforce password complexity in a Linux environment.
Enforcing Password Complexity for Individual Users
To enforce password complexity for individual users, you can use the passwd
command with the --use-cracklib
option. This option enables the pam_cracklib
module to validate the password complexity when a user changes their password.
Example:
$ passwd --use-cracklib
Changing password for user labex.
Current password:
New password:
Retype new password:
passwd: Password updated successfully.
When the user tries to set a new password, the system will validate the password against the configured complexity rules, such as minimum length, character requirements, and password history.
Enforcing Password Complexity for System Accounts
To enforce password complexity for system accounts, such as root
or other administrative accounts, you can modify the /etc/pam.d/su
file. This file controls the authentication process for the su
command, which allows users to switch to another user account.
Add the following line to the /etc/pam.d/su
file:
auth required pam_cracklib.so try_first_pass retry=3 type=
This configuration ensures that the pam_cracklib
module is used to validate the password complexity when users attempt to switch to a system account.
Enforcing Password Complexity Across the System
To enforce password complexity across the entire system, you can modify the /etc/pam.d/common-password
file, which is the central configuration file for password-related PAM modules.
Add the following line to the /etc/pam.d/common-password
file:
password requisite pam_cracklib.so minlen=12 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1
This configuration ensures that the pam_cracklib
module is used to validate the password complexity for all user accounts when they change or create new passwords.
By implementing these enforcement mechanisms, you can ensure that users within your Linux environment adhere to the configured password complexity policies, enhancing the overall security of your system.