系统初始化脚本
1)设置时区并把同步时间加入计划任务
2)禁用selinux
3)历史命令显示操作时间
4)创建ALL权限用户并禁止root远程登录
5)安装常用工具
#/usr/bin/bash
##这是初始化系统脚本
ntp_date () {
date
echo “时间对时成功”
sleep 2
}
close_selinux (){
cat /etc/sysconfig/selinux | grep ‘SELINUX=disable’
if [ $? -eq 0 ];then
echo " close selinux successsful!"
else
echo " close selinux faild ,please check"
fi
echo “selinux 关闭成功”
sleep 2
}
set_histime(){
echo ‘HISTTIMEFORMAT="%F %T "’ >> /etc/profile
echo “export HISTTIMEFORMAT” >>/etc/profile
sleep 1
echo “history 成功”
sleep 2
}
install_tools (){
yum install -y vim &>>/dev/null
yum install -y wget &>>/dev/null
echo “安装成功!”
}
ssh_deroot (){
useradd jack
sed -r -i.bak ‘93i\jack ALL=(ALL) ALL’ /etc/sudoers
echo “用户创建成功”
sed -r -i.bak ‘1i\PermitRootLogin No’ /etc/ssh/sshd_config
systemctl restart sshd
}
ping -c1 www.baidu.com
if [ $? -eq 0 ];then
echo “正在对系统初始化…”
sleep 1
else
echo “net is bad check net!”
systemctl restart network
ifup ens33
ping -c1 www.baidu.com
if [ $? 0 ];then
echo "net recover "
else
echo "net can’t recover "
exit
fi
fi
ntp_date
wait
close_selinux
wait
set_histime
wait
install_tools
wait
ssh_deroot