欢迎光临散文网 会员登陆 & 注册

Debian安装fail2ban防止暴力破解

2023-07-22 14:18 作者:今冷与夕暖  | 我要投稿

在安装fail2ban之前,建议将ssh服务配置为通过密钥登录并禁止密码登录。这样既可以增强安全性,也可以避免fail2ban启动后因忘记密码或输错密码导致正常登录被封禁。其他操作系统详见:https://github.com/fail2ban/fail2ban/wiki

1.安装软件

apt-get install -y fail2ban

2.启动并设置开机启动

systemctl start fail2ban

systemctl enable fail2ban

3.新建配置文件jail.local,上传到/etc/fail2ban目录下

这个是精简版的配置文件,官方文件地址:https://github.com/mikechau/fail2ban-configs/blob/master/jail.local

不要修改jail.conf和fail2ban.conf,原因详见:https://github.com/fail2ban/fail2ban/wiki/Proper-fail2ban-configuration



[DEFAULT]

ignoreip = 127.0.0.1

findtime = 60

maxretry = 1

bantime  = -1

banaction = iptables-multiport


[ssh]

enabled  = true

port     = ssh

filter   = sshd

logpath  = /var/log/auth.log

maxretry = 1


4.上传配置后,重载服务

service fail2ban reload

5.查看封禁IP

fail2ban-client status sshd

7.查看运行状态

journalctl -ru fail2ban

8.解禁IP

fail2ban-client set sshd unbanip IP_ADDRESS

9.查看登录失败日志

lastb

10.清除登录失败日志

cd /var/log

echo > /var/log/btmp

echo > /var/log/btmp.1

参考资料:

https://its.pku.edu.cn/faq_fail2ban.jsp

https://github.com/fail2ban/fail2ban/wiki







Debian安装fail2ban防止暴力破解的评论 (共 条)

分享到微博请遵守国家法律