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 June 4, 2022November 22, 2024 by Mingyu Zhu

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

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

步骤一:修改 /etc/pam.d/common-password-pc 配置文件

# vim /etc/pam.d/common-password-pc

将以下内容:

......
password	requisite	pam_cracklib.so ......
......

修改为:

......
password        requisite       pam_cracklib.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=5
......

并添加以下内容:

......
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) pam_cracklib.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
......
maxrepeat = 5
......
retry = 3
......
difok = 3
......

(
补充:这里以
1) 密码最小长度为 15 个字符 (minlen = 15)
2) 密码必须包含数字的个数 (dcredit = -1)
3) 密码必须包含大写字母的个数 (ucredit = -1)
4) 密码必须包含小写字母的个数 (lcredit = -1)
5) 密码必须包含特殊字符的个数 (ocredit = -1)
6) 密码不能包含字典 (dictcheck = 1)
7) 密码不能包含用户 (usercheck = 1)
8) 新密码不能和前 5 个老密码重复 (maxrepeat=5)
9) 3 次尝试错误密码后产生错误提示 (retry=3)
10) 新密码最多可以有 3 个字符和旧密码相同 (difok=3)
为例
)

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

# 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 [步骤] Linux 密码的安全 (设置密码复杂度和加密算法) (CentOS 7 & RHEL 7 版)
Next PostNext [工具] Shell 批量检测指定用户是否可以登录本地服务器

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