CentOS安全漏洞修補指南
在修補前,需先明確系統受影響的漏洞范圍??赏ㄟ^以下方式確認:
cat /etc/centos-release
);修補操作前,務必備份關鍵數據和配置文件,防止操作失誤導致數據丟失。需備份的內容包括:
/etc/ssh/sshd_config
、/etc/sysconfig/iptables
);/home
目錄、數據庫文件);/var/lib/mysql
目錄)。使用yum
(CentOS 7及以下)或dnf
(CentOS 8及以上)命令更新系統和軟件包,這是修復已知漏洞的核心步驟:
sudo yum update -y
(或sudo dnf update -y
),系統會自動檢查并安裝可用的安全更新;sudo yum update openssh openssl -y
。為減少人工操作風險,建議配置自動更新安全補丁的工具:
sudo yum install yum-cron -y
;/etc/yum/yum-cron.conf
,設置以下參數為yes
:update_cmd=security
(僅更新安全補?。?、update_messages=yes
(發送更新通知)、download_updates=yes
(下載補?。?、apply_updates=yes
(自動應用補?。?;sudo systemctl start yum-cron
、sudo systemctl enable yum-cron
。sudo yum install unattended-upgrades -y
;sudo dpkg-reconfigure --priority=low unattended-upgrades
(選擇“是”開啟安全更新);sudo systemctl start unattended-upgrades
、sudo systemctl enable unattended-upgrades
。若漏洞涉及Linux內核(如CVE-2024-1086),需升級內核版本以修復:
sudo yum -y update
;sudo yum --enablerepo=elrepo-kernel install kernel-ml -y
;sudo grub2-mkconfig -o /boot/grub2/grub.cfg
;sudo reboot
,重啟后通過uname -r
確認內核版本已更新。修補漏洞后,需通過配置強化系統安全性,降低后續被攻擊的風險:
firewalld
(推薦)或iptables
限制不必要的網絡訪問,例如僅允許SSH(端口22)和HTTP(端口80)流量:sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
systemctl list-unit-files --type=service
查看運行中的服務,禁用不需要的服務(如telnet
、ftp
):sudo systemctl stop telnet && sudo systemctl disable telnet
;/etc/ssh/sshd_config
文件,設置PermitRootLogin no
(禁止root遠程登錄)、PasswordAuthentication no
(禁用密碼登錄,改用密鑰認證)、Port 2222
(修改默認端口),然后重啟SSH服務:sudo systemctl restart sshd
;fail2ban
防止暴力破解,配置自動封禁多次登錄失敗的IP:sudo yum install fail2ban -y
,編輯/etc/fail2ban/jail.local
啟用SSH防護。修補后需定期檢查系統安全性,及時發現新的漏洞:
OpenVAS
(開源漏洞掃描器),定期掃描系統以識別潛在漏洞;journalctl -xe
(實時日志)或logwatch
(日志分析工具)查看系統日志,及時發現異常登錄、文件修改等行為;/etc/passwd
中的用戶權限)、軟件版本(如ssh -V
、openssl version
),確保符合安全標準。