Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)
Posted on August 6, 2020November 22, 2024 by Mingyu Zhu

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

  • 步骤一:设置密码必须包含大小写字母等策略
  • 步骤二:设置新密码不能和旧密码重复的策略以及加密算法
    • 2.1 配置 authselect 自定义认证
      • 2.1.1 检查是否选择了 authselect 自定义认证
      • 2.1.2 如果 authselect 自定义认证存在
      • 2.1.2.1 修改 /etc/authselect/custom/password-policy/system-auth 配置文件
      • 2.1.2.2 修改 /etc/authselect/custom/password-policy/password-auth 配置文件
      • 2.1.3 如果 authselect 自定义认证不存在
      • 2.1.3.1 生成新的 authselect 自定义认证
      • 2.1.3.1.1 备份当前的 authselect 自定义认证
      • 2.1.3.1.2 创建新的 authselect 自定义认证
      • 2.1.3.1.3 选择新的 authselect 自定义认证
      • 2.1.3.1.3.1 选择新的 authselect 自定义认证
      • 2.1.3.1.3.2 满足选择新的 authselect 自定义认证时 with-mkhomedir 参数的要求
      • 2.1.3.1.4 显示当前选择的 authselect 自定义认证
      • 2.1.3.2 修改 authselect 自定义认证
      • 2.1.3.2.1 修改 /etc/authselect/custom/password-policy/system-auth 配置文件
      • 2.1.3.2.2 修改 /etc/authselect/custom/password-policy/password-auth 配置文件
    • 2.2 让配置的 authselect 自定义配置认证生效
  • 步骤三:设置加密算法

步骤一:设置密码必须包含大小写字母等策略

# 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)
为例
)

步骤二:设置新密码不能和旧密码重复的策略以及加密算法

2.1 配置 authselect 自定义认证

2.1.1 检查是否选择了 authselect 自定义认证
# authselect current | awk 'NR == 1 {print $3}' | grep custom/
custom/password-policy

(
补充:
(1)如果这条命令里没有输出则代表没有选择自定义认证
(2)从这里的输出结果可以看出这里选择的自定义认证是 custom/password-policy
)

2.1.2 如果 authselect 自定义认证存在
2.1.2.1 修改 /etc/authselect/custom/password-policy/system-auth 配置文件
# vim /etc/authselect/custom/password-policy/system-auth

将以下内容:

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

修改为:

...... 
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=5 use_authtok ......
......
password    sufficient    pam_unix.so sha512 shadow try_first_pass use_authtok remember=24 use_authtok ......
......

(
补充:这里以
1) 新密码不能和前 5 个旧密码重复
2) 使用 SHA512 哈希算法加密密码
为例
)

2.1.2.2 修改 /etc/authselect/custom/password-policy/password-auth 配置文件
# vim /etc/authselect/custom/password-policy/password-auth

将以下内容:

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

修改为:

...... 
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=5 use_authtok ......
......
password    sufficient    pam_unix.so sha512 shadow try_first_pass use_authtok remember=24 use_authtok ......
......

(
补充:这里以
1) 新密码不能和前 5 个旧密码重复
2) 使用 SHA512 哈希算法加密密码
为例
)

2.1.3 如果 authselect 自定义认证不存在
2.1.3.1 生成新的 authselect 自定义认证
2.1.3.1.1 备份当前的 authselect 自定义认证
# authselect apply-changes -b --backup=sssd.backup

(补充:这里以创建 sssd.backup 备份文件为例)

2.1.3.1.2 创建新的 authselect 自定义认证
# authselect create-profile password-policy -b sssd --symlink-meta --symlink-pam

(补充:这里以生成名为 password-policy 的自定义认证为例)

2.1.3.1.3 选择新的 authselect 自定义认证
2.1.3.1.3.1 选择新的 authselect 自定义认证
# authselect select custom/password-policy with-sudo with-faillock without-nullok with-mkhomedir --force

(
补充:
1) 这里以选择名为 password-policy 的自定义认证为例
2) 这里设置了 with-sudo、with-faillock、without-nullok 和 with-mkhomedir 参数
)

(注意:使用了 with-mkhomedir 参数后,会提示需要开启 oddjobd)

2.1.3.1.3.2 满足选择新的 authselect 自定义认证时 with-mkhomedir 参数的要求
# dnf install oddjob ; systemctl enable --now oddjobd.service
2.1.3.1.4 显示当前选择的 authselect 自定义认证
# authselect current

(补充:这里以生成并选择名为 password-policy 的自定义认证为例)

2.1.3.2 修改 authselect 自定义认证
2.1.3.2.1 修改 /etc/authselect/custom/password-policy/system-auth 配置文件
# vim /etc/authselect/custom/password-policy/system-auth

将以下内容:

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

修改为:

...... 
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=5 use_authtok ......
......
password    sufficient    pam_unix.so sha512 shadow try_first_pass use_authtok remember=24 use_authtok ......
......

(
补充:这里以
1) 新密码不能和前 5 个旧密码重复
2) 使用 SHA512 哈希算法加密密码
为例
)

2.1.3.2.2 修改 /etc/authselect/custom/password-policy/password-auth 配置文件
# vim /etc/authselect/custom/password-policy/password-auth

将以下内容:

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

修改为:

...... 
password    requisite     pam_pwhistory.so try_first_pass local_users_only enforce-for-root remember=5 use_authtok ......
......
password    sufficient    pam_unix.so sha512 shadow try_first_pass use_authtok remember=24 use_authtok ......
......

(
补充:这里以
1) 新密码不能和前 5 个旧密码重复
2) 使用 SHA512 哈希算法加密密码
为例
)

2.2 让配置的 authselect 自定义配置认证生效

# authselect apply-changes

(注意:此步骤会刷新 /etc/authselect/system-auth 配置文件和 /etc/authselect/password-auth 配置文件)

步骤三:设置加密算法

# vim /etc/login.defs

将以下内容:

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

修改为:

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

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

CategoriesChinese Post (中文帖子), System (系统), System Login Security (系统登录安全), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件), System Security (系统安全), System Setting (系统设置), System Setting Other Steps (系统设置其它步骤), System Setting Others (系统设置其它)

Post navigation

Previous PostPrevious [工具] Shell 批量修改多个远程服务器某个用户的过期密码
Next PostNext [步骤] Linux 文件或目录的查找 (特殊权限)

Aspiration (愿景):

Everyone can achieve self-achievement and self-happiness fairly

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

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress