1-服务器基础操以及安全配置

  • Xshell和CRT都属于远程的软件,网络上存在破解版本。以SecCRT为例.

    配置ssh操作的输入输出(D:\data\ssh\ssh-log%S-%Y%M%D.log)

    配置本地机器上的上传和下载目录(使用rz、sz)

    实现批量部署和管理的功能

    捕获1

  • centos在社区可以下载。

系统初级模板搭建以及系统的安全优化

  • 关闭selinux

    管理文件为/etc/selinux/config

    方法1:永久关闭selinux,重启生效。
    [root@B ~]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    方法2:临时关闭,一般与方法一一同使用
    [root@B ~]# setenforce 
    usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
    [root@B ~]# setenforce 0
    [root@B ~]# getenforce 
    Permissive
    
  • 设置运行级别

    管理文件为/etc/inittab

    [root@B ~]# grep "runlevel 3" /etc/inittab 
    # multi-user.target: analogous to runlevel 3
    
    systemctl set-default multi-user.target
    [root@localhost ~]# systemctl set-default multi-user.target
    
  • 精简开机自启动

    [root@localhost ~]# for service in `chkconfig --list|grep 3:on` ;do chkconfig --level 3 $service off ;done
    [root@localhost ~]# for service in crond network rsyslog sshd sysstat ;do chkconfig --level 3 $serverice on ;done
    
    Centos7
    [root@localhost ~]# systemctl list-unit-files|grep enabled
    [root@localhost ~]#for service in `systemctl list-unit-files|grep enabled` ;do systemctl disable $service ;done
    [root@localhost ~]# for A in crond network rsyslog sshd sysstat ;do systemctl enable $A ;done
    
  • 关闭iptables

    [root@localhost ~]# systemctl stop firewalld.service 
    
  • 配置ssh服务器远端登录

    sed -ir '13 iport 52113\nPermitRootLogin no\nPermitEmptyPasswords no\n' /etc/ssh/sshd_config
    [root@localhost ~]# egrep "port 52113|PermitRootLogin|PermitEmptyPasswords" /etc/ssh/sshd_config
    port 52113
    PermitRootLogin no
    PermitEmptyPasswords no
    UserDNS no
    #PermitRootLogin yes
    #PermitEmptyPasswords no
    # the setting of "PermitRootLogin without-password".
    
  • 利用sudo进行权限划分( https://blog.csdn.net/a19881029/article/details/18730671 )

    审计:查看文档C:\Users\admin\Desktop\笔记\linux系统学习\服务器审计

    ######Create by sxq at first###
     Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient\
    , /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig\
    , /sbin/mii-tool
    ## Installation and management of software 软件安装管理相关命令别名
     Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
    
    ## Services 服务相关命令别名
     Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
    
    ## Updating the locate database 本地数据库升级命令别名
     Cmnd_Alias LOCATE = /usr/bin/updatedb
    
    ## Storage 磁盘操作相关命令别名
     Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe\
    , /bin/mount, /bin/umount
    
    ## Delegating permissions 代理权限相关命令别名
     Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
    
    ## Processes 进程相关命令别名
     Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
    
    ## Drivers 驱动命令别名
     Cmnd_Alias DRIVERS = /sbin/modprobe
    ####################################################################################################
    #用户别名  新名称   =用户名、用户组(%组名)
    
     #User_Alias NetworkAdmin= sxq
     #User_Alias Audoit_Admin = %audit
    ##Runas_Alias ###
    Runas_Alias  OP = root
    #pri config
    #用户名   机器=(权限角色) 可执行的命令
    NetworkAdmin ALL=(op) SOFTWARE,SERVICES,LOCATE,STORAGE
    #superadmin  ALL=(ALL) NOPASSWD:ALL
    #超级用户不需要密码可以登录
    #safe        ALL=(ALL)ALL,/usr/bin/passwd [A-Za-z]*,!/usr/bin/passwd root\
    #                          \  !/usr/sbin/visudo,!/usr/bin/vi *sudoer*
    #safe具备所有权限,但不可以更改密码(root)和visudo的内容
    
    
  • 设置时间同步

    [root@localhost ~]# echo '*/5 * * * * /sbin/ntpdate time.nist.gov >/dev/null 2>&1' >> /var/spool/cron/root
    
  • 历史记录以及登录超时的环境变量设置(/etc/profile)

    [root@localhost admin]# echo 'export HISTSIZE=5' >> /etc/profile
    [root@localhost admin]# echo 'export HISTFILESIZE=5' >> /etc/profile
    [root@localhost admin]# echo 'export TMOUT=600' >>/etc/profile
    [root@localhost admin]# tail -3 /etc/profile
    export TMOUT=600
    export HISTSIZE=5
    export HISTFILESIZE=5
    
  • 调整Linux系统的文件描述符数量

    [root@localhost security]# echo '* - nofile 65535' >> /etc/security/limits.conf 
    [root@localhost security]# tail -1 /etc/security/limits.conf 
    * - nofile 65535
    
  • 定时清理邮件的临时目录垃圾文件()

    [root@localhost maildrop]# mkdir -p /server/scripts/
    [root@localhost maildrop]# echo "find /var/spool/postfix/maildrop/ -type f |xargs rm -f" /server/scripts/del_file.sh 
    [root@localhost maildrop]# cat /server/scripts/del_file.sh 
    find /var/spool/postfix/maildrop/ -type f |xargs rm -f
    echo "0 0 * * * /bin/sh /server/scrpits/del_file.sh >/dev/null 2&>1">> /var/spool/cron/root
    
  • 锁定关键目录防止提权篡改(chart +i)

    [root@localhost maildrop]# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab 
    [root@localhost maildrop]# which chattr
    /bin/chattr
    [root@localhost maildrop]# mv /bin/chattr /bin/key
    [root@localhost maildrop]# key -i /etc/passwd
    
  • 清除多余的系统虚拟账户

  • 为grub菜单进行加密(在开机以及重启时调整grub进行加密)

    grub-md5-crypt
    
  • 禁止Linux系统被ping

    [root@localhost maildrop]# iptables -t filter -I INPUT -p icmp --icmp-type 8 -s 10.0.0.0/24 -j ACCEPT
    
  • 升级具有典型漏洞版本的软件

  • 添加静态路由

    [root@localhost maildrop]# ip route add 0.0.0.0/0 via 192.168.31.200 dev ens33
    [root@localhost maildrop]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.31.200  0.0.0.0         UG    0      0        0 ens33
    
    永久生效
    [root@localhost network-scripts]# echo " 0.0.0.0/0 via 192.168.31.200 dev ens33" >> /etc/sysconfig/network-scripts/route-ens33
    
    
    
posted @ 2020-02-28 15:14  shanheoldman  阅读(70)  评论(0)    收藏  举报