如何部署服务器安全软件?
美国、香港服务器
如何部署服务器安全软件?
07-06 来源:
1. Fail2ban(防 SSH / 后台暴力破解,自动拉黑攻击 IP)
安装
bash
运行
sudo apt update
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
核心配置
bash
运行
# 复制本地配置(不修改原文件)
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
写入通用规则(适配自定义 SSH 端口 22345):
ini
[DEFAULT]
bantime = 3600 # 封禁1小时
findtime = 600 # 10分钟窗口
maxretry = 5 # 5次失败拉黑
backend = systemd
[sshd]
enabled = true
port = 22345
logpath = %(sshd_log)s
[nginx-http-auth]
enabled = true
logpath = /var/log/nginx/error.log
[nginx-botscan]
enabled = true
filter = nginx-botsearch
logpath = /var/log/nginx/access.log
重载生效:
bash
运行
sudo systemctl restart fail2ban
# 查看封禁列表
sudo fail2ban-client status sshd
2. ClamAV 开源杀毒(查杀 WebShell、挖矿病毒、恶意脚本)
安装全套组件
bash
运行
sudo apt install clamav clamav-daemon clamav-freshclam -y
更新病毒库(关键,安装后先更新)
bash
运行
# 停止自动更新服务,手动更新库
sudo systemctl stop clamav-freshclam
sudo freshclam
# 重启服务开机自启
sudo systemctl enable --now clamav-freshclam clamav-daemon
手动扫描常用目录
bash
运行
# 扫描网站目录,发现病毒隔离到隔离文件夹
clamscan -r --move=/var/quarantine /var/www
# 扫描临时木马目录
clamscan -r /tmp /var/tmp /dev/shm
定时凌晨自动扫描(cron)
bash
运行
sudo crontab -e
# 每天3点扫描网站+临时目录,输出日志
0 3 * * * clamscan -r --move=/var/quarantine /var/www /tmp >> /var/log/clamav/daily_scan.log
3. Rkhunter + Chkrootkit(Rootkit 内核后门查杀,挖矿 / 隐藏木马专用)
安装
bash
运行
sudo apt install rkhunter chkrootkit -y
使用方法
bash
运行
# 更新病毒特征库
sudo rkhunter --update
# 全系统扫描(--sk跳过交互)
sudo rkhunter -c --sk
# 简易rootkit扫描
sudo chkrootkit
定时巡检写入计划任务
bash
运行
0 4 * * * rkhunter -c --sk >> /var/log/rkhunter.log
4. Lynis(系统安全审计工具,一键输出加固报告)
自动检测端口、弱密码、漏洞、不安全配置、自启后门
bash
运行
sudo apt install lynis -y
# 执行完整审计
sudo lynis audit system
扫描结尾会给出大量安全修复建议,逐条整改即可。
5. AIDE 文件完整性监控(入侵检测 IDS,监控系统文件篡改)
黑客篡改 /etc/passwd、ssh 密钥、系统二进制会立刻告警
bash
运行
sudo apt install aide -y
# 初始化基线数据库
sudo aideinit
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
# 每日对比文件变更
0 5 * * * aide --check >> /var/log/aide_check.log
6. AppArmor(Ubuntu 自带强制访问控制,限制程序越权)
限制 Nginx、SSH、数据库进程只能访问指定目录,即使 Web 被入侵也无法横向渗透
bash
运行
# 查看运行状态
sudo aa-status
# 启用所有配置文件
sudo aa-enforce /etc/apparmor.d/*
sudo systemctl restart apparmor
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快