sudo apt update
sudo apt install fail2ban -y
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 你设置的端口
backend = systemd
logpath = %(sshd_log)s
maxretry = 5
bantime = 1h
findtime = 10m
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
检查 Fail2Ban 状态
sudo fail2ban-client status
sudo fail2ban-client status sshd
你将看到类似输出:
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 5
| `- File list: /var/log/auth.log
`- Actions
|- Currently banned: 1
|- Total banned: 2
`- Banned IP list: 192.168.1.100