系统配置重复项处理:经验未必可靠
| 特性 | /etc/profile | /etc/ssh/sshd_config |
|---|---|---|
| 重复项处理 | 最后一个生效 | 第一个生效 |
| 错误处理 | 静默覆盖 | 记录警告,忽略重复 |
| 验证命令 | source /etc/profile; echo $VAR | sshd -T |
| 调试方法 | set -x; source /etc/profile | sshd -t 或 sshd -d |
| 多值支持 | 不支持,会覆盖 | 某些参数支持多值(如AllowUsers) |
这里以/etc/profile(系统级配置)和sshd_config(应用级配置)为例进行说明。
如上总结大体上如此!尤其是“系统级配置”一惯性比较好。“应用级配置”在该应用的不同版本中表现不一。不同的配置项重复配置处理逻辑也不一样。
例如:sshd_config中的Port,配置多个均会生效
注:OpenSSH_8.0p1, OpenSSL 1.1.1k FIPS 25 Mar 2021,低版本未验证,不保证一致性。
~]# sshd -T|grep -i port
port 22
port 1220~]# ss -tlnp|grep ssh
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1602139,fd=5))
LISTEN 0 128 0.0.0.0:1220 0.0.0.0:* users:(("sshd",pid=1602139,fd=3))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1602139,fd=6))
LISTEN 0 128 [::]:1220 [::]:* users:(("sshd",pid=1602139,fd=4))
例如:sshd_config中的MaxStartups,配置多个最后一个生效
~]# cat /etc/ssh/sshd_config| grep -i MaxStartups
MaxStartups 10:30:60
MaxStartups 10:30:100~]# sshd -T|grep -i max
maxstartups 10:30:100
总结
不要对配置型进行重复性配置,可能有时候我们的经验可能失效。例如最上面的总结性经验。在sshd_config中就失效了。最后可能导致非预期生效的结果。进而导致业务不可用或者安全性降低。
