您的位置:首页 > 运维架构 > Linux

linux防暴力破解远程密码神器-fail2ban

2016-09-22 21:01 591 查看
安装:fail2ban
[root@xuegod63 ~]# tar -zxvf fail2ban-0.8.14.tar.gz
[root@xuegod63 fail2ban-0.8.14]# cdfail2ban-0.8.14
查看安装指南README.md
[root@xuegod63 ~]# cdfail2ban-0.8.14
[root@xuegod63fail2ban-0.8.14]#python setup.py install
生成服务启动脚本:[root@xuegod63fail2ban-0.8.14]# cp files/redhat-initd /etc/init.d/fail2ban
[root@xuegod63fail2ban-0.8.14]# chkconfig --add fail2ban
[root@xuegod63fail2ban-0.8.14]# chkconfig --listfail2ban
fail2ban 0:off 1:off 2:off 3:on 4:on 5:on 6:off

设置条件:ssh远程登录5分钟内3次密码验证失败,禁止用户IP访问主机1小时,1小时该限制自动解除,此IP可以重新登录。
[root@xuegod63 ~]# vim /etc/fail2ban/jail.conf #改以下红色标记内容

[ssh-iptables]

enabled =true
filter = sshd
action = iptables[name=SSH, port=ssh,protocol=tcp]
sendmail-whois[name=SSH,dest=you@example.com, sender=fail2ban@example.com,sendername="Fail2Ban"]
logpath = /var/log/secure
findtime = 300 #需要新添加
maxretry = 3
bantime = 3600 #需要新添加

启动服务:[root@xuegod63 fail2ban-0.8.14]#servicefail2ban start
Starting fail2ban: [确定]

测试

查看fail2ban服务运行状态:
[root@xuegod63fail2ban]# fail2ban-clientstatus #配置好之后我们检测下fail2ban是否工作。
Status
|-Number of jail: 1
`-Jail list: ssh-iptables

[root@xuegod63fail2ban]# fail2ban-client status ssh-iptables
#具体看某一项的状态也可以看,如果显示被ban的ip和数目就表示成功了,如果都是0,说明没有成功。
Statusfor the jail: ssh-iptables
|-filter
| |- File list: /var/log/secure
| |- Currently failed: 0
| `- Total failed: 3
`-action
|- Currently banned: 1
| `-IP list: 192.168.1.2
`- Total banned: 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 密码 暴力