Skip to content

Eternal Center

  • Single Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Other (其它)
    • Ideas (思路)
    • Language (语言)
    • Project (项目)
  • Eternity (永恒)
    • Creations (创作)
    • Classics (经典)
    • Chronicle (编年史)
    • News (消息)
Posted on June 4, 2022August 30, 2022 by Mingyu Zhu

[步骤] Linux 密码的安全 (设置密码复杂度和加密算法) (CentOS 7 & RHEL 7 版)

  • 步骤一:修改 /etc/pam.d/system-auth-ac 配置文件
  • 步骤二:修改 /etc/pam.d/password-auth-ac 配置文件
  • 步骤三:修改 /etc/security/pwquality.conf 配置文件
  • 步骤四:修改 /etc/login.defs 配置文件

步骤一:修改 /etc/pam.d/system-auth-ac 配置文件

# vim /etc/pam.d/system-auth-ac

将以下内容:

......
password    requisite     pam_pwquality.so ......
......
password    requisite     pam_pwhistory.so ......
......
password    sufficient    pam_unix.so
......

修改为:

......
password    requisite     pam_pwquality.so try_first_pass local_users_only enforce-for-root minlen=15 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1 maxrepeat=5 retry=3 difok=3 remember=24
......
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=24 use_authtok
......
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=24
......

(
补充:这里以
1) pam_pwquality.so 模块使用前 1 个模块从用户那里得到的密码 (try_first_pass)
2) 只作用于本地用户 (local_users_only)
3) 也作用于 root 用户 (enforce-for-root)
4) 密码最小长度为 15 个字符 (minlen=15)
5) 密码必须包含数字的个数 (dcredit=-1)
6) 密码必须包含大写字母的个数 (ucredit=-1)
7) 密码必须包含小写字母的个数 (lcredit=-1)
8) 密码必须包含特殊字符的个数 (ocredit=-1)
9) 最多只允许 5 个连续字符 (maxrepeat=5,如果是 0 则禁用该选项)
10) 3 次尝试错误密码后产生错误提示 (retry=3)
11) 新密码最多可以有 3 个字符和旧密码相同 (difok=3)
12) 新密码不能和最近用过的 24 个密码相同 (remember=24)
13) 使用 sha512 加密方法加密 (sha512)
为例
)

步骤二:修改 /etc/pam.d/password-auth-ac 配置文件

# vim /etc/pam.d/password-auth-ac

将以下内容:

......
password    requisite     pam_pwquality.so ......
......
password    requisite     pam_pwhistory.so ......
......
password    sufficient    pam_unix.so
......

修改为:

......
password    requisite     pam_pwquality.so try_first_pass local_users_only enforce-for-root retry=3 minlen=15 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1 maxrepeat=5 difok=3 remember=24
......
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=24 use_authtok
......
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=24
......

(
补充:这里以
1) pam_pwquality.so 模块使用前 1 个模块从用户那里得到的密码 (try_first_pass)
2) 只作用于本地用户 (local_users_only)
3) 也作用于 root 用户 (enforce-for-root)
4) 密码最小长度为 15 个字符 (minlen=15)
5) 密码必须包含数字的个数 (dcredit=-1)
6) 密码必须包含大写字母的个数 (ucredit=-1)
7) 密码必须包含小写字母的个数 (lcredit=-1)
8) 密码必须包含特殊字符的个数 (ocredit=-1)
9) 最多只允许 5 个连续字符 (maxrepeat=5,如果是 0 则禁用该选项)
10) 3 次尝试错误密码后产生错误提示 (retry=3)
11) 新密码最多可以有 3 个字符和旧密码相同 (difok=3)
12) 新密码不能和最近用过的 24 个密码相同 (remember=24)
13) 使用 sha512 加密方法加密 (sha512)
为例
)

步骤三:修改 /etc/security/pwquality.conf 配置文件

# vim /etc/security/pwquality.conf

将部分内容修改如下:

......
minlen = 15
......
dcredit = -1
......
ucredit = -1
......
lcredit = -1
......
ocredit = -1
......
dictcheck = 1
......
usercheck = 1
......

(
补充:这里以
1) 密码最小长度为 15 个字符 (minlen = 15)
2) 密码必须包含数字的个数 (dcredit = -1)
3) 密码必须包含大写字母的个数 (ucredit = -1)
4) 密码必须包含小写字母的个数 (lcredit = -1)
5) 密码必须包含特殊字符的个数 (ocredit = -1)
6) 密码不能包含字典 (dictcheck = 1)
7) 密码不能包含用户 (usercheck = 1)
为例
)

步骤四:修改 /etc/login.defs 配置文件

# vim /etc/login.defs

将以下内容:

......
ENCRYPT_METHOD ......
......

修改为:

......
ENCRYPT_METHOD SHA512
......

(补充:这里以使用 SHA512 哈希算法加密密码为例)

CategoriesChinese (中文), System (系统), System Login Security (系统登录安全), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件), System Security (系统安全), System Setting (系统设置)

Post navigation

Previous PostPrevious [CONTENT] Linux Enterprise Agreements and Product Appendices
Next PostNext [步骤] Linux 密码的安全 (设置密码复杂度和加密算法) (openSUSE & SLE 版)

Aspiration (愿景):

Everyone can achieve self achievement and self happiness fairly

每个人都能公平地实现自我成就和自我幸福

Position (位置):

Running on Evolution Host and DigitalOcean

正在 Evolution Host 和 DigitalOcean 上运行

Logo (徽标):

Additional Information (其他信息):

About Manual Clone Contact
Disclaimer Donation Friendly Links
关于 说明书 克隆 联系
免责申明 捐赠 友情链接

Standby IP Address (备用 IP 地址):

152.69.204.95  150.230.63.10  Please configure before use / 请先配置再使用

Search Outside Website (站外搜索):

Google Wikipedia Bing
Proudly powered by LNMP Proudly powered by WordPress