CentOS Stream系统安全加固:轻松上手,全方位防护指南

引言
CentOS Stream是一个基于Linux内核的操作系统,它为开发者提供了一个接近上游Linux内核的体验。由于其与上游社区的紧密集成,CentOS Stream在安全性方面可能会面临一些挑战。本文将为您提供一系列简单的步骤,帮助您在CentOS Stream系统上实施安全加固措施,确保系统安全。
1. 更新系统
确保您的系统是最新的,以便安装所有安全补丁。使用以下命令更新系统:
sudo dnf update
2. 配置防火墙
使用
firewalld
配置防火墙,以允许必要的流量,同时拒绝所有其他未经授权的访问。
sudo systemctl start firewalld
sudo systemctl enable firewalld
创建自定义规则以允许特定服务或端口:
sudo firewall-cmd –permanent –add-service=http
sudo firewall-cmd –permanent –add-service=https
sudo firewall-cmd –reload
3. 使用SELinux
SELinux(Security-Enhanced Linux)是一种安全模块,它可以提供额外的安全层。启用SELinux以确保只有授权的应用程序可以执行敏感操作:
sudo setenforce 1
或者,如果您想要设置SELinux为宽容模式,可以使用以下命令:
sudo setenforce 0
4. 配置SSH
SSH是远程登录服务,默认情况下,它是不安全的。以下是一些配置SSH的建议:
更改SSH默认端口(如使用
2222
代替
22
):
sudo sed -i ‘s/^#Port 22/Port 2222/’ /etc/ssh/sshd_config
sudo systemctl restart sshd
启用SSH密码认证:
sudo sed -i ‘s/^PasswordAuthentication no/PasswordAuthentication yes/’ /etc/ssh/sshd_config
sudo systemctl restart sshd
强制使用密钥认证:
sudo sed -i ‘s/^#PubkeyAuthentication yes/PubkeyAuthentication yes/’ /etc/ssh/sshd_config
sudo systemctl restart sshd
5. 安装安全软件
安装一些安全软件,如 fail2ban 和 Fail2Ban,以帮助防御暴力破解攻击:
sudo dnf install fail2ban
配置Fail2Ban以保护SSH服务:
sudo cp /etc/fail2ban/jail.d/sshd.conf /etc/fail2ban/jail.d/custom-sshd.conf
sudo sed -i ‘s/^enabled = yes/enabled = no/’ /etc/fail2ban/jail.d/custom-sshd.conf
sudo systemctl restart fail2ban
6. 使用强密码策略
确保所有用户都使用强密码,并定期更换密码。您可以使用
pwgen
工具生成强密码:
sudo pwgen 12 1
7. 定期备份
定期备份系统数据,以防数据丢失或损坏。
sudo rsync -a /path/to/backup/directory/ /path/to/backup/location/
8. 监控和日志审计
配置系统日志记录,并定期检查日志文件以查找潜在的安全威胁。
sudo vi /etc/syslog.conf
在
syslog.conf
中,确保所有关键服务的日志都被记录。
结论
通过遵循上述步骤,您可以在CentOS Stream系统上实施全面的安全加固措施。请记住,安全性是一个持续的过程,需要定期审查和更新安全策略。