在当今云计算环境中,RockyLinux安全加固已成为保障业务连续性和数据安全的关键环节。作为RHEL的社区替代品,RockyLinux因其稳定性、兼容性和开源特性被广泛用于企业级云服务器部署。然而,默认安装的系统往往存在安全风险,本文将手把手教你如何对RockyLinux进行全方位的安全加固,即使是Linux小白也能轻松上手。
首先,确保系统为最新状态,并移除不必要的软件包,这是云服务器安全配置的第一步。
sudo dnf update -ysudo dnf autoremove -y
建议在安装时选择“Minimal Install”(最小安装),避免预装非必要服务如图形界面、打印服务等,减少攻击面。
RockyLinux默认使用firewalld作为防火墙工具。应仅开放必要的端口(如SSH的22端口、Web服务的80/443等)。
# 启动并启用防火墙sudo systemctl enable --now firewalld# 查看当前区域sudo firewall-cmd --get-active-zones# 仅允许SSH(假设使用默认22端口)sudo firewall-cmd --permanent --add-service=ssh# 如果运行Web服务,再添加HTTP/HTTPSsudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --permanent --add-service=https# 重载配置sudo firewall-cmd --reload
SSH是远程管理的主要入口,必须重点加固。编辑SSH配置文件:
sudo vi /etc/ssh/sshd_config
修改以下关键参数(取消注释并调整):
# 禁用root直接登录PermitRootLogin no# 仅允许特定用户(如youruser)登录AllowUsers youruser# 修改默认端口(可选但推荐)Port 2222# 禁用密码认证,强制使用密钥登录PasswordAuthentication noPubkeyAuthentication yes
保存后重启SSH服务:sudo systemctl restart sshd。务必先测试新配置是否能正常连接!
SELinux是RockyLinux内置的强制访问控制机制,应保持启用(enforcing模式)以增强RockyLinux系统安全。
# 检查SELinux状态sestatus# 若未启用,编辑配置文件sudo vi /etc/selinux/config# 确保以下行存在SELINUX=enforcing
同时,安装auditd记录关键系统事件:
sudo dnf install audit -ysudo systemctl enable --now auditd
使用OpenSCAP进行合规性扫描,并配置自动安全更新:
# 安装OpenSCAPsudo dnf install scap-security-guide openscap-scanner -y# 执行CIS基准扫描(示例)sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis \--report /tmp/cis-report.html \/usr/share/xml/scap/ssg/content/ssg-rl9-ds.xml# 配置自动安全更新sudo dnf install dnf-automatic -yecho 'apply_updates = yes' | sudo tee -a /etc/dnf/automatic.confsudo systemctl enable --now dnf-automatic.timer
通过以上步骤,你已为RockyLinux云服务器构建了坚实的安全基础。记住,企业级Linux安全不是一次性任务,而是一个持续的过程。建议定期审查日志、更新策略,并关注RockyLinux官方安全公告。安全无小事,从今天开始加固你的云环境吧!
本文由主机测评网于2025-12-06发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025123991.html