防止 CentOS 被 exploit(漏洞利用)入侵,需要从系统加固、漏洞管理、权限控制、网络防护、监控审计等多方面入手。下面按实战优先级给你一套可落地的方案。
yum update -y
或(CentOS 8+):
dnf update -y
✅ 开启自动安全更新:
yum install yum-cron -y
systemctl enable yum-cron
exploit 常利用“开着的服务”
systemctl list-unit-files --type=service | grep enabled
关闭示例:
systemctl stop telnet.socket
systemctl disable telnet.socket
编辑:
vi /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
systemctl restart sshd
✅ 使用 SSH 密钥登录
只开放必要端口:
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
yum install epel-release -y
yum install fail2ban -y
systemctl enable fail2ban
rpm -qa | grep 软件名
getenforce
若为 Disabled:
vi /etc/selinux/config
SELINUX=enforcing
重启后生效
✅ SELinux 能阻止大量本地 exploit
yum install openscap-scanner
yum install clamav clamav-update
vi /etc/sysctl.conf
添加:
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
kernel.randomize_va_space=2
sysctl -p
usermod -s /sbin/nologin appuser
cat /etc/passwd
lastlog
/var/log/secure
/var/log/messages
安装:
yum install logwatch
yum install aide
aide --init
✅ 及时打补丁
✅ 关服务、限端口
✅ 禁 root + 密钥登录
✅ 开 SELinux
✅ 装 Fail2Ban
✅ 常看日志
如果你愿意,我可以:
你现在是 CentOS 几?物理机还是云?主要跑什么服务?