fail2ban 这个软件第一次用大概是10年前了。最近个人机器一直被暴力破解,这里安装一下,防止ssh暴力破解。fail2ban可以基于防火墙屏蔽ip也可以基于hosts.deny ,这里基于hosts.deny配置。
[root@oracledb ~]# yum install epel-release
[root@oracledb ~]# yum search fail2ban
[root@oracledb ~]# yum install fail2ban fail2ban-systemd fail2ban-hostsdeny
配置
[root@oracledb ~]# vim /etc/fail2ban/jail.conf
[sshd]
enabled = true
maxretry = 3
port = 60022
logpath = %(sshd_log)s
backend = %(sshd_backend)s
action = hostsdeny
bantime = 86400
findtime = 60
启动
[root@oracledb ~]# systemctl start fail2ban
[root@oracledb ~]# systemctl enable fail2ban
查看被屏蔽的ip
[root@oracledb ~]# fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 27
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 1
|- Total banned: 1
`- Banned IP list: 138.197.76.252
[root@oracledb ~]# cat /etc/hosts.deny
ALL: 138.197.76.252
也可以自己找个机器使用错误密码实验几次,这里不再演示。