在Debian系统下配置安全策略是一个涉及多个方面的过程,旨在提高系统的整体安全性。以下是一些关键步骤和建议:
sudo apt update && sudo apt upgrade
sudo systemctl list-units --type=service --state=running | sudo grep -v "enabled.service" | sudo xargs sudo systemctl disable
ufw 或 iptables 等工具限制入站和出站流量。sudo apt install ufw # 安装ufw
sudo ufw enable # 启用ufw
sudo ufw allow 22/tcp # 允许SSH端口
sudo ufw allow 80/tcp # 允许HTTP端口
sudo ufw allow 443/tcp # 允许HTTPS端口
sudo ufw reload # 重新加载ufw规则
sudo apt install libpam-pwquality # 安装PAM密码质量工具
sudo nano /etc/pam.d/commonpassword # 编辑PAM配置文件
# 在文件中添加或修改以下行来定义密码策略
password requisite pam_cracklib.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1
sudo 代替直接登录为root用户。sudo adduser newuser # 创建新用户
sudo usermod -aG sudo newuser # 将用户添加到sudo组
sudo nano /etc/ssh/sshd_config # 编辑SSH配置文件
# 更改端口号
Port 2222
# 禁用root登录
PermitRootLogin no
# 使用SSH密钥对认证
PasswordAuthentication no
PubkeyAuthentication yes
# 重启SSH服务
sudo systemctl restart ssh
Logwatch 或 Fail2ban 自动监控并报告系统活动。sudo apt install logwatch # 安装Logwatch
sudo systemctl enable logwatch # 启用Logwatch服务
sudo systemctl start logwatch # 启动Logwatch服务
通过上述步骤和建议,您可以显著提高Debian系统的安全性,保护您的数据和系统免受潜在的威胁。