Linux服务器安全设置

  1. 设置密码失效时间
    查看当前的设置
    chage -l root

    设置修改密码最大间隔时间,60天
    chage -M 60 root
  2. 是指密码修改最小间隔时间
    设置修改密码最小间隔时间,10天
    chage -m 10 root
  3. 设置SSH空闲超时退出时间
    vim /etc/ssh/sshd_config
    
    放开注释,修改值
    ClientAliveInterval 600
    ClientAliveCountMax 3
  4. 密码复杂度检查
    检查密码长度和密码是否使用多种字符类型
    vim /etc/security/pwquality.conf
    
    把minlen(密码最小长度)设置为9-32位,把minclass(至少包含小写字母、大写字母、数字、特殊字符等4类字符中等3类或4类)设置为3或4。
    minlen = 9
    minclass = 3
  5. 检查密码重用是否受限制
    在/etc/pam.d/password-auth和/etc/pam.d/system-auth中password sufficient pam_unix.so 这行的末尾配置remember参数为5-24之间,原来的内容不用更改,只在末尾加了remember=5。
    vim /etc/pam.d/password-auth
    
    追加remember=5
    password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5:q
  6. 禁止使用root登录
    新增一个用户用来登录
    useradd test
    
    设置密码
    passwd test

    修改/etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:
    vim
    /etc/sudoers

      ## Allow root to run any commands anywhere
      root ALL=(ALL) ALL
      vlson ALL=(ALL) ALL



    修改SSHD配置,禁用root登录 vim /etc/ssh/sshd_config 找到“#PermitRootLogin yes 修改PermitRootLogin后面的yes为no,并且去掉前面的注释符,同时可以限制失败次数 PermitRootLogin no MaxAuthTries 3

    重启SSHD服务
    service sshd restart
  7. 拓展ssh暴力破解
    定义:不断通过ssh尝试密码登录服务器
    
    基本防御:更换默认的22端口号,设置IP白名单,只有特定IP的用户才可以访问。
    修改ssh端口号:
    使用root用户vim /etc/ssh/sshd_config

      放开Port 22注释,并增加你想更换的端口号

      Port 22
      Port 12435

      重启sshd:centos 7使用:systemctl restart sshd.service