云服务器安全加固完整指南
服务器安全加固是保护数据安全的关键措施。
1. 修改SSH端口
编辑SSH配置文件:
vi /etc/ssh/sshd_config
修改端口:
Port 22222
重启SSH服务:
systemctl restart sshd
2. 禁用root远程登录
创建普通用户:
useradd admin
passwd admin
添加sudo权限:
usermod -aG wheel admin
禁用root登录:
vi /etc/ssh/sshd_config
PermitRootLogin no
3. 配置防火墙
CentOS使用firewalld:
- firewall-cmd --permanent --add-port=22222/tcp
- firewall-cmd --permanent --add-port=80/tcp
- firewall-cmd --permanent --add-port=443/tcp
- firewall-cmd --reload
4. 使用SSH密钥登录
生成密钥对:
ssh-keygen -t rsa -b 4096
上传公钥到服务器:
ssh-copy-id user@server
禁用密码登录:
PasswordAuthentication no
5. 安装fail2ban防暴力破解
- yum install fail2ban -y
- systemctl start fail2ban
- systemctl enable fail2ban
6. 定期更新系统
yum update -y
7. 最小化安装原则
只安装必需的软件包