一、修复前的准备工作
/etc/ssh/sshd_config、/etc/sysconfig/iptables)、用户数据(如/home目录)及数据库(如MySQL的/var/lib/mysql),防止操作失误导致数据丢失。二、通用修复步骤
yum(CentOS 7)或dnf(CentOS 8及以上)命令更新系统至最新版本,修复已知安全漏洞:# CentOS 7
sudo yum update -y
# CentOS 8及以上
sudo dnf update -y
sudo yum update wget -y
/etc/yum/yum-cron.conf,设置update_messages=yes、download_updates=yes、apply_updates=yes,然后启动并启用服务:sudo systemctl start yum-cron
sudo systemctl enable yum-cron
# 添加ELRepo源
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
# 安装最新内核
sudo yum --enablerepo=elrepo-kernel install kernel-ml -y
# 重启系统并选择新内核
sudo reboot
sudo systemctl restart sshd
sudo systemctl restart httpd
sudo reboot
yum list updates,确认无可用安全更新;或使用漏洞扫描工具(如OpenVAS、Nessus)重新扫描系统,验证漏洞是否修复。三、针对性加固措施
firewalld限制网络访问,仅开放必要端口(如SSH的22端口):sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --remove-port=22/tcp # 若端口非22,需调整
sudo firewall-cmd --reload
/etc/ssh/sshd_config),禁用root直接登录、设置强密码(要求包含大小写字母、数字、特殊字符)并更改默认端口(如2222):PermitRootLogin no
PasswordAuthentication yes
Port 2222
sudo systemctl restart sshd
sudo systemctl stop telnet
sudo systemctl disable telnet
games、ftp)及未使用的账号,避免被利用:sudo userdel games
sudo userdel ftp
/etc/login.defs),设置密码最小长度(如8位)、过期时间(如90天):PASS_MIN_LEN 8
PASS_MAX_DAYS 90
fail2ban防止暴力破解,配置自动封禁多次登录失败的IP:sudo yum install fail2ban -y
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
sudo setenforce 1
sudo sed -i 's/SELINUX=permissive/SELINUX=enforcing/g' /etc/selinux/config
四、后续维护建议
journalctl或logwatch监控系统日志,关注异常登录(如频繁的失败登录尝试)、服务异常(如SSH服务突然停止)等情况。