温馨提示×

centos minimal怎么加固

小樊
33
2026-10-17 10:32:31
栏目: 智能运维

下面给你一套CentOS Minimal(7/8/Stream 通用)系统加固清单,从“最该做”到“可选增强”,偏实战、可操作。


一、系统初始化加固(必做)

1. 更新系统

yum update -y

或(CentOS 8 / Stream):

dnf update -y

2. 创建普通用户 + sudo

useradd admin
passwd admin
usermod -aG wheel admin

编辑 sudo 配置:

visudo

确保:

%wheel ALL=(ALL) ALL

3. 禁止 root 直接登录(SSH)

vi /etc/ssh/sshd_config

修改:

PermitRootLogin no
PasswordAuthentication no   # 推荐用密钥

重启 SSH:

systemctl restart sshd

4. 配置 SSH 密钥登录

在客户端:

ssh-keygen
ssh-copy-id admin@server_ip

二、账号与权限加固

5. 锁定无用账号

passwd -l nobody

检查:

awk -F: '($3==0)' /etc/passwd

只应有 root 和管理员


6. 设置密码策略

vi /etc/login.defs

示例:

PASS_MAX_DAYS 90
PASS_MIN_DAYS 1
PASS_MIN_LEN 12
PASS_WARN_AGE 7

强制密码复杂度:

yum install -y libpwquality

编辑:

/etc/security/pwquality.conf
minlen = 12
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1

三、网络与防火墙

7. 启用 firewalld

systemctl enable --now firewalld

只开放必要端口:

firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --reload

8. 关闭不必要的服务

systemctl list-unit-files --type=service | grep enabled

停用示例:

systemctl disable --now postfix

四、安全增强(强烈推荐)

9. 启用 SELinux

getenforce

若为 disabled:

vi /etc/selinux/config
SELINUX=enforcing

重启系统。


10. 安装 fail2ban(防爆破)

yum install -y epel-release
yum install -y fail2ban
systemctl enable --now fail2ban

示例配置:

/etc/fail2ban/jail.local
[sshd]
enabled = true
maxretry = 3
bantime = 3600

五、日志与审计

11. 启用 auditd

systemctl enable --now auditd

监控重要文件:

auditctl -w /etc/passwd -p wa -k passwd_changes

12. 日志集中(可选)

  • rsyslog → 远程日志服务器
  • 或 filebeat + ELK

六、内核与系统参数

13. 防 SYN flood / IP 欺骗

vi /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
sysctl -p

七、自动化与维护

14. 自动安全更新(可选)

yum install -y dnf-automatic
vi /etc/dnf/automatic.conf
apply_updates = yes
systemctl enable --now dnf-automatic.timer

八、最小化原则(核心思想)

✅ 不装 GUI
✅ 不装不需要的服务
✅ 不开放多余端口
✅ 不用弱密码
✅ 不用 root 日常操作


如果你愿意,我可以:

  • 给你一份 一键加固脚本
  • 针对 CentOS 7 / 8 / Stream 分别说明
  • 按 等保 / CIS 标准给清单

你现在是 CentOS 几?物理机还是云服务器?

0 踩