linux 安全配置随笔

1. 禁止Ctrl+Alt+Del直接重启服务器

    /bin/mv /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak

2. 使用强密码

    密码不得少于8位,并且需要同时包含大、小字母,数字和特殊字符;避免使用常见的单词。

    设置:

    sed -i "s/password requisite pam_cracklib.so.*/password required pam_cracklib.so try_first_pass retry=6 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 enforce_for_root/g" /etc/pam.d/system-auth

3. 连续6次输错密码禁用一段时间,设置为300秒

    sed -i "/#%PAM-1.0/aauth required pam_tally2.so onerr=fail deny=6 unlock_time=300 even_deny_root root_unlock_time=300" /etc/pam.d/system-auth

4. 记录用户上次登录时间

    echo "LASTLOG_ENAB yes" >>/etc/login.defs

5. 设置空闲时间和history配置

    echo "export TMOUT=600" >>/etc/profile

    echo "export HISTFILESIZE=5000" >>/etc/profile

    source /etc/profile

    echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/bashrc

    source /etc/bashrc

6. SSH服务安全策略 

    a) 禁止使用root账户通过SSH方式登录;

      echo "PermitRootLogin no" >>/etc/ssh/sshd_config

    b) 修改SSH服务的空闲等待时间

      echo "ClientAliveInterval 300" >>/etc/ssh/sshd_config

    c) 设置SSH连接尝试次数 

      echo "MaxAuthTries 3" >>/etc/ssh/sshd_config

    修改完以后需要重新启动SSH服务生效

      service sshd restart

原文地址:https://www.cnblogs.com/zqingfeng/p/6808367.html