Files
Linux/Docs/系统安全策略配置.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

1.3 KiB
Raw Blame History

本文作者:丁辉

系统安全策略配置

限制 Linux 最大限制远程登录次数

方法一

  1. 编辑 SSH 服务配置文件

    vi /etc/ssh/sshd_config
    

    修改如下内容

    # 设置每个IP地址的最大登录尝试次数
    MaxAuthTries 3
    
    # 设置封锁的时间单位为秒这里设置为300秒即5分钟
    LoginGraceTime 300
    
  2. 重载配置

    systemctl reload sshd
    

方法二

  1. 安装 fail2ban

    yum install epel-release -y
    yum install fail2ban -y
    
  2. 配置 fail2ban

    cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    

    编辑jail.local文件,找到并更改以下参数

    # 设置ban的时间以秒为单位默认值为600秒即10分钟
    bantime = 600
    
    # 允许尝试登录的最大次数
    maxretry = 5
    
    # 将这个值设置为yesfail2ban将禁止任何主机的IP如果该主机的IP多次失败这对于保护你的系统非常有用。
    # 但要谨慎使用,以防止合法用户因错误登录被阻止。
    banaction = iptables-multiport
    
  3. 启动 fail2ban 服务

    systemctl start fail2ban
    systemctl enable fail2ban
    
  4. 检查fail2ban状态

    fail2ban-client status