fail2ban安装配置(防止ssh暴力破解)

Linux安全
1198
linux
linux 举报
2020-03-14

1.下载源码包:

[root@localhostlocal]源码包下载地址:

https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.8.14spm=a2c4e.11153940.blogcont195078.15.19df49734mpYvn&file=0.8.14

 

2.解压编译安装

[root@localhost local]# tar -zxvf fail2ban-0.8.14.tar.gz

[root@localhost local]# cd fail2ban-0.8.14

[root@localhost fail2ban-0.8.14]#python setup.py install

 

3.手动生成启动脚本

[root@localhost fail2ban-0.8.14]#cp files/redhat-initd /etc/init.d/fail2ban

[root@localhost fail2ban-0.8.14]#chkconfig --add fail2ban

[root@localhost fail2ban-0.8.14]#chkconfig --list fail2ban

 

4.修改/etc/fail2ban/jail.conf 文件实现防护规则配置

[root@localhost fail2ban-0.8.14]#vim /etc/fail2ban/jail.conf

[DEFAULT] #全局设置

ignoreip = 127.0.0.1/8 #忽略的IP列表,不受设置限制

bantime = 600#屏蔽时间,单位:秒

findtime = 600 #这个时间段内超过规定次数会被ban掉

maxretry = 3 #最大尝试次数

backend = auto #日志修改检测机制(gamin、polling和auto这三种)

然后是sshd程序防护设置

[ssh-iptables]

enabled = true #启用配置

filter = sshd #规律规则名,对应filter.d目录下的sshd.conf

action = iptables[name=SSH, port=ssh, protocol=tcp]

logpath = /var/log/secure #检测的系统的登陆日志文件。这里要写sshd服务日志文件

bantime = 3600 #禁止用户IP访问主机1小时

findtime = 300 #在5分钟内内出现规定次数就开始工作

maxretry = 3 #3次密码验证失败

 

5.防火墙加入相关规则并重启

[root@localhost fail2ban-0.8.14]#iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name ROUTER-SSH  --update --seconds 1800 --hitcount 5 -j DROP

[root@localhost fail2ban-0.8.14]#iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name ROUTER-SSH --set -j ACCEPT

[root@localhost fail2ban-0.8.14]#service iptables restart

 

6.启动fail2ban服务

先创建日志文件

[root@localhost fail2ban-0.8.14]#touch /var/log/sshd.log

[root@localhost fail2ban-0.8.14]#service fail2ban restart

原文地址:https://www.cnblogs.com/jasmine-Jobs/p/5927968.html


倒序看帖 只看楼主
热点关注
postfix中的main.cf 中的一些部分详细说明
在后台用进程名运行bash脚本
shell脚本每行后面多了一个^M的原因和解决办法
定时检测服务,检测down掉后重启。系统检测到DMSERVER运行正常
挂载磁盘的时候遇到一个问题,挂载完磁盘之后重启服务器挂载的盘丢失了.
中标麒麟系统Your trial is EXPIRED and no VALID licens
termux 开启ssh并用用户名和密码登陆
组成共享库的目标文件和一般的目标文件有所不同,在编译时要加-fPIC和-share选项,例如:
gcc指定链接库路径后还是找不到库文件
./configure -build,-host,-target设置
关于Linux系统中configure中build,target,host中的若干问题
不用单独编译gmp、mpfr和mpc三个包,放在gcc源码下面一起编译
shell参数判断
服务停止、启动、重启一体化脚本,万能语言启动脚本
postfix下过滤垃圾邮件的有效方法