在Linux服务器上进行安全配置是一个复杂的过程,涉及多个方面。以下是一些关键步骤和建议,帮助你提高服务器的安全性:
sudo apt update && sudo apt upgrade -y
sudo ufw enable
sudo ufw allow 22/tcp # 允许SSH
sudo ufw allow 80/tcp # 允许HTTP
sudo ufw allow 443/tcp # 允许HTTPS
sudo ufw status
sudo systemctl list-units --type=service --state=enabled
sudo systemctl disable <service_name>
/etc/ssh/sshd_config
文件,更改默认的SSH端口。Port 2222
PermitRootLogin no
PasswordAuthentication no
sudo setenforce 1
sudo sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config
chmod 755 /etc/passwd
chmod 644 /etc/shadow
sudo apt install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
rsync
或tar
进行定期备份。sudo rsync -avz / /backup/location
sudo tail -f /var/log/auth.log
sudo tail -f /var/log/syslog
OpenSCAP
或Lynis
进行安全审计。sudo lynis audit system
sudo apt install certbot
sudo certbot --nginx -d yourdomain.com
通过以上步骤,你可以显著提高Linux服务器的安全性。记住,安全是一个持续的过程,需要定期审查和更新配置。