Home > Article > Operation and Maintenance > How to set a strong password policy on Linux
How to set a secure password policy on Linux
Introduction:
In the information age, protecting the sensitive information of individuals and enterprises is crucial. Passwords are one of the most commonly used authentication methods.
In Linux systems, we can increase the security of account passwords by setting strong password policies to protect the security of our computers and data.
This article will introduce how to set a secure password policy on Linux, and attach relevant code examples.
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0 Full sample code:
sudo vi /etc/login.defs
# 设置密码有效期为90天 PASS_MAX_DAYS 90
# 设置密码最小使用期限为7天 PASS_MIN_DAYS 7
# 设置密码最小长度为8位 PASS_MIN_LEN 8
sudo apt-get install libpam-cracklib
Then, we need to edit the pam configuration file /etc/pam.d/common-password and add the following lines in the file:
# 密码强度检查 password requisite pam_cracklib.so retry=3 minlen=8 difok=3
The parameter retry here indicates the number of times the system requires the user to re-enter the password when the user enters a weak password.
The parameter minlen represents the minimum password length, which is recommended to be the same as the PASS_MIN_LEN set previously.
The parameter difok indicates at least how many different characters the password must contain.
# 密码强度检查 password requisite pam_cracklib.so retry=3 minlen=8 difok=3 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1
# 设置密码过期前的警告期限为7天 PASS_WARN_AGE 7
# 强制用户在下次登录时修改密码 sudo chage -d 0 username
Summary:
By appropriately adjusting and optimizing the password policy on the Linux system, we can increase the security of the account password.
The steps introduced above include modifying the password validity period, minimum usage period and length, setting the password strength check policy and forcing password changes, etc.
By following these steps and making appropriate adjustments based on the actual situation, we can improve the security of our passwords and effectively protect the security of our systems and data.
References:
The above is the detailed content of How to set a strong password policy on Linux. For more information, please follow other related articles on the PHP Chinese website!