防范 CentOS 系统的 exploit(漏洞利用),核心思路是:减少攻击面 + 及时修补 + 严格权限 + 多层防护。下面按实战优先级给你一套可操作的防护方案。
yum update -y
或仅更新安全补丁:
yum update --security
yum install yum-cron -y
systemctl enable yum-cron
systemctl start yum-cron
编辑:
/etc/yum/yum-cron.conf
确保:
apply_updates = yes
systemctl list-units --type=service --state=running
systemctl disable 服务名
systemctl stop 服务名
常见高危服务:
vim /etc/ssh/sshd_config
PermitRootLogin no
ssh-keygen
ssh-copy-id user@server
并禁用密码登录:
PasswordAuthentication no
Port 22222
重启 SSH:
systemctl restart sshd
getenforce
若为 Disabled,改为:
vim /etc/selinux/config
SELINUX=enforcing
重启生效。
编辑:
/etc/sysctl.conf
kernel.randomize_va_space = 2
net.ipv4.ip_forward = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
生效:
sysctl -p
vim /etc/security/pwquality.conf
minlen = 12
dcredit = -1
ucredit = -1
passwd -l 用户名
systemctl enable firewalld
systemctl start firewalld
只开放必要端口:
firewall-cmd --permanent --add-port=22222/tcp
firewall-cmd --reload
yum install epel-release -y
yum install fail2ban -y
配置 SSH 防护:
vim /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 22222
maxretry = 3
bantime = 3600
systemctl enable auditd
systemctl start auditd
last
lastb
journalctl -xe
yum install aide -y
aide --init
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
aide --check
| 版本 | 状态 |
|---|---|
| CentOS 7 | 已 EOL(2024-06-30) |
| CentOS 8 | 已 EOL |
| CentOS Stream | 滚动更新 |
✅ 建议:
rpm -qa | grep 软件名
https://access.redhat.com/security/cve/
CentOS 防 exploit = 及时更新 + 少开服务 + 强 SSH + SELinux + 防火墙 + 日志监控 + 尽快迁移新系统
如果你愿意,我可以:
直接告诉我你的 CentOS 版本 + 服务器用途 即可。