- [root@localhost ~]# cd fail2ban-0.8.11
- [root@localhost fail2ban-0.8.11]# python setup.py install
- [root@localhost fail2ban-0.8.11]# cd files/
- [root@localhost files]# cp ./redhat-initd /etc/init.d/fail2ban
- [root@localhost files]# service fail2ban start
- [root@localhost files]# chkconfig –add fail2ban
- [root@localhost files]# chkconfig fail2ban on
注:需要配置 iptables 实用,如果重启 iptables 了也要重启 fail2ban,因为 fail2ban 的原理是调用 iptables 实时阻挡外界的攻击。
- [root@localhost ~]# grep -v "^#" /etc/fail2ban/jail.conf | grep -v "^$"
- [DEFAULT]
- ignoreip = 127.0.0.1/8# 忽略本机 IP
- bantime = 600 #符合规则后封锁时间
- findtime = 600 # 在多长时间内符合规则执行封锁如 600 秒达到 3 次则执行
- maxretry = 3 # 最大尝试次数
- backend = auto #日志修改检测日志 gamin、polling 和 auto 这三种
- usedns = warn
- [ssh-iptables]
- enabled = true# 默认是禁用 false
- filter = sshd
- action = iptables[name=SSH, port=ssh, protocol=tcp]
- # sendmail-whois[name=SSH,dest = 收件人邮箱, sender = 发件人邮箱, sendername="Fail2Ban"]
- logpath = /var/log/sshd.log # 响应的错误日志一般在 / var/log/secure
- maxretry = 5 # 尝试错误次数覆盖全局中的 maxretry
注:默认所有的应用防护都是关闭的,需要我们手动开启。fail2ban.conf 文件是日志信息,jail.conf 文件是保护的具体服务和动作配置信息。
- [root@localhost ~]# touch /var/log/sshd.log
- [root@localhost ~]# service fail2ban restart
- [root@localhost ~]# fail2ban-client status # 查看监控已经开启
- Status
- |- Number of jail: 1
- `- Jail list: ssh-iptables
- [root@localhost ~]# iptables -L #iptables 过滤表有 fail2ban 一条规则
- fail2ban-SSH tcp — anywhere anywhere tcp dpt:ssh
连接会话终端持续化 – Tmux
Tmux 是一个优秀的终端复用软件类似 GNU Screen 比 Screen 更加方面、灵活和高效。为了确保连接 SSH 时掉线不影响任务运行。
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm(安装第三方 YUM 源)