CentOS 6.5 Linux系统安全初始化脚本

来源:互联网 发布:java网上购物系统源码 编辑:程序博客网 时间:2024/06/10 07:44

CentOS 6.5 Linux System Security init Scripts  (Linux系统安全初始化脚本)  

备注:此脚本主要是整合日常系统安全配置事项,但暂未进行相应的判断,如有兴趣的童鞋可以进行相应的修改和优化,谢谢!

cat /usr/local/scripts/system_security_init.sh

#!/bin/bash
# This is System Security init
# Write by'Mike.liweizhong
# Email lwz_benet@163.com
# Technology blog  http://liweizhong.blog.51cto.com
# Version 04.8.10
# System Version CentOS 6.5




###变量,自行修改自己需要创建的用户名和初始化密码
User="user01 user02"
PWD_init="passwd2014"


###创建维护账号,使用sudo提升执行权限,限制用户使用SU切换ROOT用户
mkdir /home/operator
for i in $User
do
useradd  -d /home/operator/$i  $i
echo "$PWD_init" |passwd --stdin $i &> /dev/null
chage -d 0 $i
gpasswd -a $i wheel 
done

sed -i "108s/^# //g" /etc/sudoers
sed -i "6s/^#//g"  /etc/pam.d/su 


###禁用ROOT使用SSH远程登录,修改SSH默认端口
#sed -i "s/#Port 22/Port 20014/g" /etc/ssh/sshd_config
sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config
service sshd restart


###更改系统登录提示,隐藏系统版本信息
rm -rf /etc/issue
rm -rf /etc/issue.net
echo "Welcome to Gosafe Linux Server" > /etc/issue
echo "Welcome to Gosafe Linux Server" > /etc/issue.net


###限制记录命令历史的条数,设置闲置超时自动注销终端
sed -i "s/HISTSIZE=1000/HISTSIZE=100/g" /etc/profile
sed -i "49 i\TMOUT=300" /etc/profile
#echo "history -c" >> ~/.bash_logout


###限制用户的密码有效期200天(最大天数)
sed -i "25s/99999/200/g" /etc/login.defs


###限制用户密码的最小长度
sed -i "15s/type=/minlen=12/g" /etc/pam.d/system-auth


###实时监控用户操作,此地方在引用变量$USER-$UID有点小BUG,会引用当前系统变量,
mkdir /usr/local/user_info_log
chmod a+w /usr/local/user_info_log
#cat >> /etc/profile << EFF
#if [ $UID -ge 500 ]; then
#exec /usr/bin/script -t 2>/usr/local/user_info_log/$USER-$UID-`date +%Y%m%d%H%M`.date  -a -f -q /usr/local/user_info_log/$USER-$UID-`date +%Y%m%d%H%M`.log
#fi
#EFF


###SSH登录验证失败封锁IP脚本
#bad_ip=$( lastb -i -a | grep ssh | awk '{print $NF}' | sort |uniq -c | awk '$1>3 {print $2}')
#for i in $bad_ip
#do
# echo "sshd: $i" >> /etc/hosts.deny
#done
#echo "" > /var/log/btmp


###锁定不希望更改的系统文件
#chattr +i /etc/passwd /boot/grub/grub.conf 
echo "System Security init finish !!!"

0 0
原创粉丝点击