赞
踩
#!/bin/bash # #*********************************************************************** #Author:ZHANGhaodong #Date:2021-12-09 #FileName:kylin_security_force_20211209.sh #Installation:Mini #SystemOS(适用os): 1.Kylin Linux Advanced Server release V10 (SP2) /(Sword)-x86_64-Build09/20210524 # 2. #Function: # 1.修改已经存在的账户的密码过期时间 # 2.修改用户命令提示符 # 3.关闭selinux # 4.关闭防火墙,NetworkManager,iptables等服务 # 5.设置口令失效提示 # 6.禁止root远程登陆 # 7.设置登陆失败账户锁定策略 # 8.设置密码复杂度 # 9.设置口令生存周期 # 10.设置口令重复使用次数 # 11.删除或锁定无关账号 # 12.禁止root远程telnet登录 # 13.设置ssh登录策略 # 14.设置用户所需最小权限 # 15.检查别名文件配置 # 16.启用cron行为日志功能 # 17.禁止ICMP重定向 # 18.关闭IP转发 # 19.设置登录超时策略 # 20.设置历史记录输出条数 # 21.修改SNMP服务默认团体字 # 22.设置ssh登陆前警告 # 23.禁止不必要的系统账号ftp登录 # 24.限制ftp用户权限 # 25.禁止匿名ftp登录 #*********************************************************************** . /etc/init.d/functions Optional="Optional" Mandatory="Mandatory" function insert { local file=$1 local type=$2 local msg=$3 local line_num=$(cat -n $file | grep -w $type | head -1 | awk '{print $1}') local num=$[ $line_num-1 ] sed -i "${num}a $msg" $file } function backup_cfgfile { #配置文件要写绝对路径 local cfgfile=$1 local bakfile=$cfgfile.bak.$(date +"%Y_%m_%d-%H:%M:%S") test -e $cfgfile && /bin/cp -f $cfgfile $bakfile && echo $bakfile >> /tmp/bakfile } function prt_msg { local level=$1 local msg=$2 printf "[%-10s] %-50s " $level "$msg" } function get_release { egrep -q "VERSION_ID" /etc/os-release | awk -F'"' '{print $2}' } function svc_ctl { local version=$(get_release) local op=$1 local svcname=$2 case $version in 6.*) test -e /etc/rd.d/init.d/$svcname on && \ case $op in enable) chkconfig $svcname on;; disable) chkconfig $svcname off;; *) service $svcname $op;; esac;; 7.*) test -e /usr/lib/systemd/system/$svcname.service && \ systemctl $op $svcname;; esac } #修改已经存在的账户的密码过期时间 function kylin_sec_change_account_expiretime { #(强制) #修改用户最短最长使用时间 2 180 # local cfgfile=/etc/passwd local name=$(cat $cfgfile | grep -wE 'bash|sh' | grep -v ^root | awk -F ":" '{print $1}') prt_msg $Mandatory "Check exist account and change expire time for password..." if [ -n "$name" ];then for i in $name do passwd -n 2 -x 180 $i 2>&1 > /dev/null done printf "OK!\n" else printf "Do not exist account,OK\n" fi } #修改用户命令提示符 function kylin_sec_login_prompt { egrep -q 'PS1' /etc/profile if [ $? -ne 0 ];then echo 'export PS1="[\u@\h \w]\\$"' >> /etc/profile . /etc/profile fi export PS1='[\u@\h \w]\\$' egrep -q 'HISTTIMEFORMAT' /etc/profile if [ $? -ne 0 ];then echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile . /etc/profile fi export HISTTIMEFORMAT="%F %T `whoami
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。