Linux 系统安全加固指南
2025-02-17
1. 系统更新与补丁管理
1 2
| sudo apt update && sudo apt upgrade -y sudo yum update -y && sudo yum upgrade -y
|
1 2
| sudo dpkg-reconfigure -plow unattended-upgrades sudo yum install yum-cron && systemctl enable yum-cron
|
2. 用户账户安全
1 2 3
| adduser securityadmin usermod -aG sudo securityadmin usermod -aG wheel securityadmin
|
1 2 3 4 5 6 7 8
| PASS_MAX_DAYS 90 PASS_MIN_DAYS 7 PASS_WARN_AGE 14
sudo apt install libpam-pwquality sudo yum install pam_pwquality
|
3. SSH 安全加固
1 2 3 4 5 6 7 8 9 10
| Port 58222 PermitRootLogin no MaxAuthTries 3 ClientAliveInterval 300 PasswordAuthentication no AllowUsers securityadmin
ssh-keygen -t ed25519 -C "admin_key"
|
4. 防火墙配置
UFW (Ubuntu/Debian):
1 2
| sudo ufw allow 58222/tcp sudo ufw enable
|
Firewalld (RHEL/CentOS):
1 2
| sudo firewall-cmd --permanent --add-port=58222/tcp sudo firewall-cmd --reload
|
5. 文件系统安全
1 2 3 4 5 6 7 8 9 10 11
| sudo chmod 700 /root sudo chmod 600 /etc/shadow
sudo chattr +i /etc/passwd sudo chattr +i /etc/group
sudo apt install aide sudo yum install aide
|
6. 审计与日志
1 2 3 4 5 6 7
| sudo apt install auditd sudo yum install audit
auditctl -w /etc/passwd -p war -k passwd_changes auditctl -w /etc/shadow -p war -k shadow_changes
|
7. 内核参数加固
编辑 /etc/sysctl.conf
:
1 2 3 4 5
| confnet.ipv4.conf.all.rp_filter=1 net.ipv4.icmp_echo_ignore_broadcasts=1 kernel.exec-shield=1 fs.protected_hardlinks=1 fs.protected_symlinks=1
|
8. 服务安全
禁用不必要服务:
1 2 3
| systemctl disable bluetooth systemctl disable cups systemctl stop avahi-daemon
|
9. 安全工具推荐
- Fail2ban:防御暴力破解
- ClamAV:恶意软件扫描
- Rkhunter:Rootkit 检测
- SELinux/AppArmor:强制访问控制
10. 备份策略
1 2 3 4 5 6 7
| 0 2 * * * tar -zcvf /backups/$(date +\%Y\%m\%d).tar.gz /etc
- BorgBackup - Rsnapshot - Duplicity
|
注意事项
- 所有修改前进行配置备份
- 生产环境修改前在测试环境验证
- 定期进行安全扫描和漏洞评估
- 启用双因素认证(2FA)
安全加固检查清单
✅ 系统更新状态
✅ SSH 密钥认证
✅ 防火墙规则验证
✅ 关键文件完整性检查
✅ 审计日志配置确认
最后更新:2025-2-17
作者:Luistin