FisherHub Blog
← 返回列表 | 工具笔记

Ubuntu 服务器安全加固清单

除了 SSH 和 UFW,这些安全措施让你的服务器更难被攻破

1. 禁用不必要的服务

# 查看所有运行的服务
systemctl list-units --type=service --state=running

# 禁用不需要的
sudo systemctl disable --now bluetooth
sudo systemctl disable --now cups  # 打印服务

2. 内核参数加固

# /etc/sysctl.d/99-security.conf
net.ipv4.tcp_syncookies = 1         # 防 SYN flood
net.ipv4.ip_forward = 0             # 禁止路由转发
net.ipv6.conf.all.disable_ipv6 = 1  # 不需要 IPv6 就关
net.ipv4.conf.all.rp_filter = 1     # 反欺骗

sudo sysctl -p /etc/sysctl.d/99-security.conf

3. 审计日志

sudo apt install auditd -y
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
sudo auditctl -w /etc/ssh/sshd_config -p wa -k sshd_changes

4. 限制用户资源

# /etc/security/limits.conf
deploy  hard  nproc  100
deploy  hard  nofile 65536

5. ClamAV 病毒扫描

sudo apt install clamav clamav-daemon -y
sudo freshclam  # 更新病毒库
sudo clamscan -r /home  # 扫描

6. 禁用 Root 登录

已经在 SSH 配置中做了,再确认一下:

sudo passwd -l root  # 锁定 root 密码

7. 定期检查

# 查看登录失败记录
sudo lastb | head -20

# 查看当前登录用户
w

# 检查可疑进程
ps aux --sort=-%cpu | head -20

# 检查开放端口
sudo ss -tlnp

安全评分卡

措施重要程度状态
SSH 密钥登录⭐⭐⭐⭐⭐
UFW 防火墙⭐⭐⭐⭐⭐
fail2ban⭐⭐⭐⭐
自动安全更新⭐⭐⭐⭐
禁用无用服务⭐⭐⭐
审计日志⭐⭐⭐
ClamAV⭐⭐

安全问题没有终点,但做完这张清单,你已经超过了 90% 的服务器。