主题
一、OpenEuler 安全加固
- 以OpenEuler 22.03 LTS SP4 发行版举例
- 参考:
1.1 确保口令复杂度设置正确
openEuler要求设置口令复杂度如下:
- 口令长度至少8个字符。
- 口令必须包含如下至少3种字符的组合:
- 至少一个小写字母。
- 至少一个大写字母。
- 至少一个数字。
- 至少一个特殊字符:`~!@#$%^&*()-_=+|[{}];:'",<.>/?和空格。
检查方法:
- /etc/pam.d/system-auth和/etc/pam.d/password-auth分别提供该功能项的配置,不同应用程序或者服务对应的配置项,需根据各自include的配置文件而定:
# grep system-auth /etc/pam.d/ -r
/etc/pam.d/login:auth substack system-auth
/etc/pam.d/login:account include system-auth
/etc/pam.d/login:password include system-auth
/etc/pam.d/login:session include system-auth
/etc/pam.d/sudo:auth include system-auth
/etc/pam.d/sudo:account include system-auth
/etc/pam.d/sudo:password include system-auth
/etc/pam.d/sudo:session include system-auth-su
以上只列举部分显示结果,从以上结果可知,login和sudo的账号认证采用/etc/pam.d/system-auth文件中的配置。
配置方法: 【以/etc/pam.d/system-auth为例进行说明】
- 在/etc/pam.d/system-auth文件中检查“设置口令复杂度”的配置情况:
bash
# 密码复杂度要求
password requisite pam_pwquality.so minlen=8 minclass=3 enforce_for_root try_first_pass local_users_only retry=3 dcredit=0 ucredit=0 lcredit=0 ocredit=0
配置项 | 说明 |
---|---|
minlen=8 | 口令长度至少包含8个字符。 说明: 建议配置更长的口令最小长度。 |
minclass=3 | 口令至少包含大写字母、小写字母、数字和特殊字符中的任意3种 |
ucredit=0 | 口令包含任意个大写字母 |
lcredit=0 | 口令包含任意个小写字母 |
dcredit=0 | 口令包含任意个数字 |
ocredit=0 | 口令包含任意个特殊字符 |
retry=3 | 每次修改最多可以尝试3次 |
enforce_for_root | 本设置对root账号同样有效 |
1.2 禁止使用历史口令
- 频繁使用相同的历史口令容易造成口令泄露而被攻击者攻击。为了用户账号的安全,需要配置“禁用历史口令”功能。根据业务实际场景,合理的设置禁用历史口令次数,但不得小于5次。
检查方法:
/etc/pam.d/system-auth和/etc/pam.d/password-auth都各自提供该功能项的配置,不同应用程序或者服务对应的配置项,需根据各自include的配置文件而定。
配置方法:
“禁用历史口令”的设置可以通过修改/etc/pam.d/password-auth和/etc/pam.d/system-auth文件实现。
- 在/etc/pam.d/system-auth文件配置如下字段:
# vim /etc/pam.d/system-auth
password required pam_pwhistory.so use_authtok remember=5 enforce_for_root
- 在/etc/pam.d/password-auth文件配置如下字段:
# vim /etc/pam.d/password-auth
password required pam_pwhistory.so use_authtok remember=5 enforce_for_root
pam_pwhistory.so配置项参数字段说明如下表:
配置项 | 说明 |
---|---|
remember=5 | 口令不能修改为过去5次使用过的旧口令 |
enforce_for_root | 本设置对root账号同样有效 |
1.3 口令有效期设置正确
- 修改/etc/login.defs文件中的默认配置,对后续新建账号口令默认生效:
bash
# 密码有效期策略
PASS_MAX_DAYS 90 # 密码最长使用天数
PASS_MIN_DAYS 0 # 密码最短使用天数
PASS_WARN_AGE 7 # 密码到期提前提醒天数
1.4 登录失败处理
规则说明:
用户使用账号登录系统,如果连续登录失败一定次数后,系统会锁定该账号登录,即一定时间内不允许该账号继续登录,防止恶意的破解系统口令。账号锁定期间,任何输入被判定为无效,锁定时间不因用户的再次输入而重新计时;解锁后,错误输入记录被清空。通过上述设置可以有效防范口令暴力破解,增强系统的安全性。系统默认设定的连续登录失败次数为3次;登录失败后,默认锁定的时间为300s。
默认配置: openEuler默认口令出错次数的阈值为3次,系统被锁定后自动解锁时间为60秒。
检查方法:
/etc/pam.d/system-auth和/etc/pam.d/password-auth分别提供该功能项的配置,不同应用程序或者服务对应的配置项,需根据各自include的配置文件而定:
# grep system-auth /etc/pam.d/ -r /etc/pam.d/login:auth substack system-auth /etc/pam.d/login:account include system-auth /etc/pam.d/login:password include system-auth /etc/pam.d/login:session include system-auth /etc/pam.d/sudo:auth include system-auth /etc/pam.d/sudo:account include system-auth /etc/pam.d/sudo:password include system-auth /etc/pam.d/sudo:session include system-auth-su
以上只列举部分显示结果,从以上结果可知,
login
和sudo
的账号认证采用/etc/pam.d/system-auth文件中的配置。后续以/etc/pam.d/system-auth为例进行说明。
在/etc/pam.d/system-auth文件中检查“连续失败登录次数”的配置情况:
# grep deny /etc/pam.d/system-auth auth required pam_faillock.so preauth audit deny=3 even_deny_root unlock_time=300 auth [default=die] pam_faillock.so authfail audit deny=3 even_deny_root unlock_time=300 auth sufficient pam_faillock.so authsucc audit deny=3 even_deny_root unlock_time=300 auth required pam_deny.so password required pam_deny.so
在/etc/pam.d/system-auth文件中检查“锁定时间”的配置情况:
# grep unlock_time /etc/pam.d/system-auth auth required pam_faillock.so preauth audit deny=3 even_deny_root unlock_time=300 auth [default=die] pam_faillock.so authfail audit deny=3 even_deny_root unlock_time=300 auth sufficient pam_faillock.so authsucc audit deny=3 even_deny_root unlock_time=300
表 6 pam_faillock.so配置项说明
配置项 | 说明 |
---|---|
authfail | 捕获用户登录失败的事件。 |
deny=3 | 用户连续登录失败次数超过3次即被锁定。 |
unlock_time=300 | 普通用户自动解锁时间为300秒(即5分钟)。 |
even_deny_root | 同样限制root帐户。 |
查看用户登录失败次数:
[root@localhost ~]# faillock --user srebro
srebro:
When Type Source Valid
2025-10-13 14:39:49 RHOST 127.0.0.1 V
2025-10-13 14:39:53 RHOST 127.0.0.1 V
2025-10-13 14:39:58 RHOST 127.0.0.1 V
手动解锁登录失败用户:
[root@localhost ~]# faillock --user srebro --reset
[root@localhost ~]# faillock --user srebro
srebro:
When Type Source Valid
1.5 会话超时设置
会话超时时间设置过长,甚至永不超时,当管理员离开时没有退出登录,其他人员就可以直接在终端上以管理员权限进行操作。 如果设置过短,则频繁锁定,增加管理员输入口令次数,降低用户体验的同时,也容易引入安全风险,管理员周边人员有较多的机会可以窥探到输入的口令。
- 修改/etc/profile文件TMOUT字段,根据业务场景修改为合理的值:
bash
#5分钟无操作自动退出
export TMOUT=300
1.6 加固SSH服务
大部分的 ssh 加固官方已经都默认加固了,请参考下面的内容:
服务端加固策略
SSH服务的所有加固项均保存在配置文件/etc/ssh/sshd_config中,服务端各加固项的含义、加固建议以及openEuler默认是否已经加固为建议加固值请参见表1。
表 1 SSH服务端加固项说明
加固项 加固项说明 加固建议 openEuler默认是否已加固为建议值 Protocol 设置使用SSH协议的版本 2 是 SyslogFacility 设置SSH服务的日志类型。加固策略将其设置为“AUTH”,即认证类日志 AUTH 是 LogLevel 设置记录sshd日志消息的层次 VERBOSE 是 X11Forwarding 设置使用SSH登录后,能否使用图形化界面 no 是 MaxAuthTries 最大认证尝试次数 3 否 PubkeyAuthentication 设置是否允许公钥认证。 yes 是 RSAAuthentication 设置是否允许只有RSA安全验证 yes 是 IgnoreRhosts 设置是否使用rhosts文件和shosts文件进行验证。rhosts文件和shosts文件用于记录可以访问远程计算机的计算机名及关联的登录名 yes 是 RhostsRSAAuthentication 设置是否使用基于rhosts的RSA算法安全验证。rhosts文件记录可以访问远程计算机的计算机名及关联的登录名 no 是 HostbasedAuthentication 设置是否使用基于主机的验证。基于主机的验证是指已信任客户机上的任何用户都可以使用SSH连接 no 是 PermitRootLogin 是否允许root帐户直接使用SSH登录系统说明:若需要直接使用root帐户通过SSH登录系统,请修改/etc/ssh/sshd_config文件的PermitRootLogin字段的值为yes。 no 否 PermitEmptyPasswords 设置是否允许用口令为空的帐号登录 no 是 PermitUserEnvironment 设置是否解析 ~/.ssh/environment和~/.ssh/authorized_keys中设定的环境变量 no 是 Ciphers 设置SSH数据传输的加密算法 aes128-ctr,aes192-ctr,aes256-ctr,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com,aes256-gcm@openssh.com 是 ClientAliveCountMax 设置超时次数。服务器发出请求后,客户端没有响应的次数达到一定值,连接自动断开 0 否 Banner 指定登录SSH前后显示的提示信息的文件 /etc/issue.net 是 MACs 设置SSH数据校验的哈希算法 hmac-sha2-512,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@openssh.com 是 StrictModes 设置SSH在接收登录请求之前是否检查用户HOME目录和rhosts文件的权限和所有权 yes 是 UsePAM 使用PAM登录认证 yes 是 AllowTcpForwarding 设置是否允许TCP转发 no 是 Subsystem sftp /usr/libexec/openssh/sftp-server sftp日志记录级别,记录INFO级别以及认证日志。 -l INFO -f AUTH 是 AllowAgentForwarding 设置是否允许SSH Agent转发 no 是 GatewayPorts 设置是否允许连接到转发客户端端口 no 是 PermitTunnel Tunnel设备是否允许使用 no 是 KexAlgorithms 设置SSH密钥交换算法 curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256 LoginGraceTime 限制用户必须在指定的时限内认证成功,0 表示无限制。缺省值是 60 秒。 60 否
二、OpenEuler 安全加固工具
2.1 工具
openEuler基于开源能力,构建相应的安全配置核查能力,主要涉及如下两个开源软件:
- openSCAP:https://gitee.com/src-openeuler/openscap
- scap-security-guide:https://gitee.com/src-openeuler/scap-security-guide
如果需要使用其对openEuler的配置安全进行核查,可按如下步骤进行操作:
安装工具(假设使用openEuler系统,并已配置正确的yum源)。
# dnf install openscap -y # dnf install scap-security-guide -y
调用oscap命令对当前系统进行核查,其中scan_results.xml和scan_report.html是核查结果文档,将详细列出每一条规范的检查结果。
# oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_standard --results scan_results.xml --report scan_report.html /usr/share/xml/scap/ssg/content/ssg-openeuler2203-ds.xml
调用oscap命令对当前系统进行加固,其中scan_results.xml和scan_report.html是加固结果文档,将详细列出每一条规范的加固结果。
# oscap xccdf eval --remediate --profile xccdf_org.ssgproject.content_profile_standard --report scan_report.html --results scan_results.xml /usr/share/xml/scap/ssg/content/ssg-openeuler2203-ds.xml
2.2 说明
1、当前工具有个别条目受限于技术及规范特点(如依赖于主观判断的条目),无法通过工具进行自动化核查,工具检查结果将显示notchecked。
2、上述命令中“ssg-openeuler2203-ds.xml”是openEuler 22.03LTS版本对应的配置文件,可以替换为其他对应版本的配置文件,此处只是举例,不再赘述。
3、安全加固条目支持加固客观项,部分主观条目无法自动加固,仍需用户手动修改,当前支持条目如下:
1.1.4 确保全局可写目录已设置sticky位
1.1.5 确保UMASK配置正确
1.1.16 确保软、硬链接文件保护配置正确
1.2.1 禁止安装FTP客户端
1.2.2 禁止安装TFTP客户端
1.2.3 禁止安装Telnet客户端
1.2.4 禁止安装不安全的SNMP协议版本
1.2.5 禁止安装python2
1.2.6 确保yum源配置GPG校验
1.2.7 禁止启用debug-shell服务
1.2.8 禁止安装rsync服务
1.2.9 禁止安装avahi服务
1.2.10 禁止安装LDAP服务
1.2.11 禁止安装打印服务
1.2.12 禁止安装NIS服务端
1.2.13 禁止安装NIS客户端
1.2.14 禁止安装LDAP客户端
2.1.4 禁止存在UID为0的非root账号
2.1.5 确保账号、组及口令文件权限正确
2.1.6 确保账号拥有自己的Home目录
2.1.7 确保/etc/passwd中的组都存在
2.2.1 确保口令复杂度设置正确
2.2.2 禁止使用历史口令
2.2.4 确保口令中不包含账号字符串
2.2.5 确保口令使用强Hash算法加密
2.2.6 确保弱口令字典设置正确
2.2.7 确保口令有效期设置正确
2.2.8 禁止空口令登录
2.2.10 确保单用户模式已设置口令保护
2.3.2 确保会话超时时间设置正确
2.3.4 应当正确配置Banner路径
2.4.4 确保su受限使用
2.4.7 确保普通用户不能借助pkexec配置提权root
2.4.8 确保su命令继承用户环境变量不会引入提权
3.3.1 确保SSH服务版本配置正确
3.3.2 确保SSH服务认证方式配置正确
3.3.3 确保SSH密钥交换算法配置正确
3.3.4 确保用户认证密钥算法配置正确
3.3.5 确保PAM认证使能
3.3.6 确保SSH服务MACs算法配置正确
3.3.7 确保SSH服务密码算法配置正确
3.3.8 禁止SSH服务配置加密算法覆盖策略
3.3.14 禁止使用X11 Forwarding
3.3.16 禁止使用PermitUserEnvironment
3.3.20 禁止SSH服务配置弃用的选项
3.3.21 确保禁用SSH的TCP转发功能
3.4.2 确保cron守护进程正常启用
3.4.3 确保at、cron配置正确
3.5.1 确保内核ASLR已启用
3.5.2 确保dmesg访问权限配置正确
3.5.3 确保正确配置内核参数kptr_restrict
3.5.4 确保内核SMAP已启用
3.5.5 确保内核SMEP已启用
3.5.6 禁止系统响应ICMP广播报文
3.5.7 禁止接收ICMP重定向报文
3.5.8 禁止转发ICMP重定向报文
3.5.10 确保丢弃伪造的ICMP报文,不记录日志
3.5.11 确保反向地址过滤已启用
3.5.12 禁止IP转发
3.5.13 禁止报文源路由
3.5.14 确保TCP-SYN cookie保护已启用
3.5.15 应当记录仿冒、源路由以及重定向报文日志
3.5.16 避免开启tcp_timestamps
3.5.17 确保TIME_WAIT TCP协议等待时间已配置
3.5.18 应当正确配置SYN_RECV状态队列数量
3.5.19 禁止使用ARP代理
3.5.21 禁止使用SysRq键
4.1.1 确保auditd审计已启用
4.1.2 确保审计日志rotate已启用
4.1.11 确保日志大小限制配置正确
4.2.1 确保rsyslog服务已启用
4.2.2 确保系统认证相关事件日志已记录
4.2.3 确保cron服务日志已记录
4.2.6 确保rsyslog转储journald日志已配置
2.3 FAQ
1、基于openeuler默认安装环境执行安全加固时,会出现如下error项(加固失败)
失败项 | 失败原因 | 解决方案 |
---|---|---|
Configure System Cryptography Policy | update-crypto-policies命令不存在 | 请安装crypto-policies后执行加固命令 |
Limit Password Reuse | 该配置项需要管理员先通过authselect配置文件,因此需要先使用authselect select选择配置 | 使用authselect list列出可用配置文件,authselect select 选择配置文件(注:如果默认的authselect配置文件不能满足特定需求,建议使用自定义的authselect配置文件。) |
Lock Accounts After Failed Password Attempts | 该配置项需要管理员先通过authselect配置文件,因此需要先使用authselect select选择配置 | 使用authselect list列出可用配置文件,authselect select 选择配置文件(注:如果默认的authselect配置文件不能满足特定需求,建议使用自定义的authselect配置文件。) |
Set Lockout Time for Failed Password Attempts | 该配置项需要管理员先通过authselect配置文件,因此需要先使用authselect select选择配置 | 使用authselect list列出可用配置文件,authselect select 选择配置文件(注:如果默认的authselect配置文件不能满足特定需求,建议使用自定义的authselect配置文件。) |
Ensure PAM Enforces Password Requirements - Authentication Retry Prompts Permitted Per-Session | 该配置项需要管理员先通过authselect配置文件,因此需要先使用authselect select选择配置 | 使用authselect list列出可用配置文件,authselect select 选择配置文件(注:如果默认的authselect配置文件不能满足特定需求,建议使用自定义的authselect配置文件。) |
Privilege escalation command audit rules should be configured | 不能自动扫描 | 请手动检查 |
Verify ip6tables Enabled if Using IPv6 | 防火墙不能同时开启 | NA |
Enable haveged service | haveged.service找不到,需要用户先安装haveged | yum install haveged |
2、基于openeuler默认安装环境执行安全扫描时,即使配置不符合openeuler规范时扫描也会显示pass项。
通过项 | 通过原因 | 解决方案 |
---|---|---|
Disable SSH Support for Rhosts RSA Authentication | openssh版本>=7.4时sshd服务会忽略相关配置。在配置相关参数的场景下,扫码脚本会先检查openssh版本,如果版本>=7.4,会直接显示检查通过 | 无需解决 |
Allow Only SSH Protocol 2 | openssh版本>=7.4时sshd服务会忽略相关配置。在配置相关参数的场景下,扫码脚本会先检查openssh版本,如果版本>=7.4,会直接显示检查通过 | 无需解决 |