zoukankan      html  css  js  c++  java
  • 使用fail2ban 防止ssh暴力破解

    fail2ban 防ssh暴力破解

    fail2ban 出现主要针对 暴力访问服务器而设计

    原理是通过linux 服务器上的访问日志,通过正则表达式,获取访问信息

    如ssh登录防暴力破解,通过正则ssh访问日志记录,获取暴利访问ip,家ip 通过防火墙隔离。

    安装

    官网 fail2ban

    # centos7
    wget "https://github.com/fail2ban/fail2ban/archive/0.9.4.tar.gz"
    ll
    tar -zxvf 0.9.4.tar.gz
    cd fail2ban-0.9.4
    python setup.py install #注意,这里需要python 2.6以上
    cp files/redhat-initd /etc/init.d/fail2ban # 启动文件添加到init.d目录
    chkconfig --add fail2ban #添加启动软链接
    

    配置

    ssh 防止暴力登录

    cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local #添加本地配置文件
    vim /etc/fail2ban/jail.local  # 自动以配置
    

    配置内容

    # 禁止ip方式
    banaction = firewallcmd-ipset  
    banaction_allports = firewallcmd-allports
    #centos7防火墙默认是 firewalld 如果是iptables,就改为iptables  目录:action.d/
    
    # sshd 配置
    [sshd]
    enabled = true  #启动
    filter = sshd #过滤规则  目录:filter.d/
    port    = 22 #拦截端口
    #logpath = %(sshd_log)s 
    logpath = /var/log/secure  #监控日志
    backend = %(sshd_backend)s 
    action = %(action_)s #封禁ip的动作
    bantime  = 172800 #ip封禁时间
    maxretry = 3  # 阈值  --同一个ip登录失败多少次后封禁ip
    

    启动

    fail2ban-client -d #检查 jail.local 配置是否正确
    systemctl start fail2ban #启动
    

    查看

    systemctl status fail2ban # 查看启动状态 running 为成功
    fail2ban-client status # 查看状态
    fail2ban-client status sshd #查看sshd 状态
    tail -f /var/log/fail2ban.log #查看fail2ban监控日志
    

  • 相关阅读:
    Git 版本导致 clone 故障
    ELK-Stack 最后一次全篇文档
    Elasticsearch 搜索引擎
    Yum -y update 报错
    Linux OOM 自动杀死进程
    MySQL 执行 'use databases;' 时很慢
    DRBD 数据镜像软件介绍
    ELK 日志管理系统,再次尝试记录
    ELK 日志管理系统,初次尝试记录
    iframe与include的区别
  • 原文地址:https://www.cnblogs.com/Narule/p/13040065.html
Copyright © 2011-2022 走看看