Linux服务器安全加固:10个必须做的配置

服务器上线前,这些安全配置必须做好!

1. 修改SSH默认端口

# 编辑 /etc/ssh/sshd_config
Port 2222  # 改成非默认端口

2. 禁用root远程登录

PermitRootLogin no

3. 使用密钥登录,禁用密码

PasswordAuthentication no

4. 安装防火墙

apt install ufw
ufw enable
ufw allow 2222/tcp

5. 自动更新安全补丁

apt install unattended-upgrades

6. 设置登录失败锁定

# /etc/pam.d/sshd
auth required pam_tally2.so deny=5 unlock_time=900

7. 关闭不用的端口和服务

systemctl disable --now 服务名

8. 安装入侵检测

apt install fail2ban

9. 定期检查日志

tail -f /var/log/auth.log

10. 备份重要数据

# 定时备份脚本
0 2 * * * /backup.sh

安全无小事,建议收藏照着做!