• Linux安全加固


    Centos 7 安全加固(最小化系统安装)

    1、锁定无用的账户

    sh-4.2# awk -F: '{print $1}' /etc/passwd | grep -E -v "root|ftp*" | xargs -n 1 passwd -l

    2、创建普通用户(以普通用户执行系统操作)

    sh-4.2# useradd -u 917 User
    sh-4.2# groupmod -g 917 User

    3、关闭ssh dns反向解析

    sh-4.2# sed -i 's:#UseDNS no:UseDNS no:' /etc/ssh/sshd_config
    sh-4.2# systemctl reload sshd.service

    4、设置密码最大有效周期

    sh-4.2# chage -d 0 User          # 初次登录必须更改密码
    sh-4.2# chage -M 90 -m 7 -W 7 User  #用户90天后密码过期,至少7天后才能修改密码,密码过期前7天开始收到告警信息
    sh-4.2# vi /etc/login.defs
    PASS_MAX_DAYS   90
    PASS_MIN_LEN    8

    5、关闭root登录权限

     

    6、设置自动退出时间

    sh-4.2# echo "TMOUT=1800" >> /etc/profile
    sh-4.2# source /etc/profile

    7、关闭linux部分快捷键

    sh-4.2# sed -i '1,$ s/^/#/' /usr/lib/systemd/system/ctrl-alt-del.target
    sh-4.2# init q

    9、修改文件系统最大打开数

    sh-4.2# sed -i '$a * soft nofile 65535' /etc/security/limits.conf
    sh-4.2# sed -i '$a * hard nofile 65535' /etc/security/limits.conf
    sh-4.2# ulimit -n 65535    # 临时设置

    10、关闭IPV6

    sh-4.2# sed -i '$a net.ipv6.conf.all.disable_ipv6 = 1' /etc/sysctl.conf 
    sh-4.2# sed -i '$a net.ipv6.conf.default.disable_ipv6 = 1' /etc/sysctl.conf
    sh-4.2# sysctl -p

    此内容参考:https://linux.cn/article-4935-1.html

    11、特殊文件权限控制

    sh-4.2# chmod 700 /usr/bin/ping
    sh-4.2# chmod 700 /usr/bin/who
    sh-4.2# chmod 700 /usr/bin/w 
    sh-4.2# chmod 700 /usr/bin/whereis
    sh-4.2# chmod 700 /usr/sbin/ifconfig
    sh-4.2# chmod 700 /usr/bin/gcc
    sh-4.2# chmod 700 /usr/bin/make
    sh-4.2# chmod 700 /usr/bin/rpm
    sh-4.2# chattr +i /etc/passwd 
    sh-4.2# chattr +i /etc/shadow 
    sh-4.2# chattr +i /etc/group 
    sh-4.2# chattr +i /etc/gshadow 
    sh-4.2# chattr +a /root/.bash_history 
    sh-4.2# chattr +i /root/.bash_history

    12、开启防火墙

    sh-4.2# rpm -qa | grep "firewall" | xargs rpm -e --nodeps
    sh-4.2# yum list iptables*
    sh-4.2# systemctl start iptables
    sh-4.2# iptables -F
    sh-4.2# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    sh-4.2# iptables -A INPUT -j DROP
    sh-4.2# service iptables save
    # 这里只是简单的列出基本的iptables规则,主要还是根据自己的业务场景进行设定

    14、系统在线升级

    15、升级openssh

  • 相关阅读:
    一个思绪凌乱的前端
    如何将你的github仓库部署到github pages(github.io博客)
    聊一聊前端系列篇
    Centos7升级gcc极简教程
    Pycharm报错连接linux服务器报错:Could not verify `ssh-rsa` host key with fingerprint
    基于Pytorch的简单小案例
    windows安装Pytorch报错:from torch._C import * ImportError: DLL load failed: 找不到指定的模块”解决方案
    scrapy抓取豆瓣电影相关数据
    scrapy结合selenium抓取武汉市环保局空气质量日报
    scrapy抓取国家社科基金项目数据库
  • 原文地址:https://www.cnblogs.com/guge-94/p/10451888.html
Copyright © 2020-2023  润新知