脚本复制粘贴保存成.sh文件即可,报错的请apt,yum下载相应的工具嗷
代码语言:javascript复制#! /bin/bash
######################################
# Linux主机安全基线检查
# Date:2020-12-23
# 使用前请给文件执行权限:chmod u x check.sh
# 如提示找不到文件 在vi编辑模式下 set ff=uninx
# by Gamma安全实验室
######################################
scanner_time=`date ' %Y-%m-%d_%H:%M:%S'`
mkdir Check_log
scanner_log="./Check_log/checkResult_${scanner_time}.log"
uptime=$(uptime | sed 's/.*up ([^,]*), .*/1/')
#调用函数库
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile
#Require root to run this script.
[ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1
#报错日志记录
[ -f ${scanner_log} ] || touch ${scanner_log}
function getSystemStatus(){
echo ""
if [ -e /etc/sysconfig/i18n ];then
default_LANG="$(grep "LANG=" /etc/sysconfig/i18n | grep -v "^#" | awk -F '"' '{print $2}')"
else
default_LANG=$LANG
fi
export LANG="en_US.UTF-8"
Release=$(cat /etc/redhat-release 2>/dev/null)
Kernel=$(uname -r)
OS=$(uname -o)
Hostname=$(uname -n)
SELinux=$(/usr/sbin/sestatus | grep "SELinux status: " | awk '{print $3}')
LastReboot=$(who -b | awk '{print $3,$4}')
uptime=$(uptime | sed 's/.*up ([^,]*), .*/1/')
echo " 系统:$OS"
echo " 发行版本:$Release"
echo " 内核:$Kernel"
echo " 主机名:$Hostname"
echo " SELinux:$SELinux"
echo "语言/编码:$default_LANG"
echo " 扫描时间:$(date '%F %T')"
echo " 最后启动:$LastReboot"
echo " 运行时间:$uptime"
export LANG="$default_LANG"
}
bk_safe(){
echo ""
echo -e "