在 CentOS(以及一般 Linux 服务器)上防止 exploit(漏洞利用) 攻击,核心思路是:减少攻击面 + 及时修补 + 权限隔离 + 监控防御。下面按优先级给你一套实用方案。
sudo yum update -y
或(CentOS 8+ / Stream):
sudo dnf update -y
✅ 开启自动安全更新:
sudo yum install yum-cron -y
sudo systemctl enable --now yum-cron
systemctl list-unit-files --type=service | grep enabled
关闭无用服务:
sudo systemctl disable --now telnet
sudo systemctl disable --now rsh
只允许必要端口:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --remove-service=http
sudo firewall-cmd --reload
✅ 禁止 root SSH 登录:
sudo sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sudo systemctl restart sshd
CentOS 默认支持:
getenforce
# 应为 Enforcing
若关闭,编辑:
/etc/selinux/config
SELINUX=enforcing
dmesgsysctl -w kernel.dmesg_restrict=1
sysctl -w kernel.modules_disabled=1
useradd -r -s /sbin/nologin appuser
chmod 700 /etc/shadow
chmod 644 /etc/passwd
定期检查 SUID 文件:
find / -perm -4000 2>/dev/null
yum install epel-release -y
yum install fail2ban -y
systemctl enable --now fail2ban
yum install aide -y
aide --init
yum install openscap-scanner
oscap xccdf eval --profile stig ...
journalctl -p err
/var/log/secure
/var/log/messages
启用 auditd:
systemctl enable --now auditd
防 exploit = 不暴露 + 不落后 + 不裸奔 + 不被提权
如果你能提供:
我可以给你一套针对性加固清单。