功能:
1、关闭Selinux
2、清空防火墙并设置基本规则
3、添加user用户并进行Sudo授权管理(根据需求添加自己的用户)
4、禁用Root远程登录
5、禁用不使用的自启动服务
6、删除不使用的系统用户
7、关闭重启组合键(ctl-alt-delete)
8、调整文件描述符大小
9、修改系统显示信息
10、修改历史记录
11、同步系统时间
12、内核参数优化
脚本如下:
#!/bin/bash
cat << EOF
±--------------------------------------+
| Start Optimize … |
±--------------------------------------+
EOF
########## Shut selinux ##########
sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config
echo “Shut selinux. [ OK ]”
########## Set firewall ##########
/sbin/iptables -F
/sbin/iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 53 -j ACCEPT
/sbin/iptables -A INPUT -p udp --dport 53 -j ACCEPT
/sbin/iptables -A INPUT -p udp --dport 123 -j ACCEPT
/sbin/iptables -A INPUT -p icmp -j ACCEPT
/sbin/iptables -P INPUT DROP
/etc/init.d/iptables save > /dev/null 2>&1
echo “Set firewall. [ OK ]”
########## Auth and add user ##########
/usr/sbin/useradd user > /dev/null 2>&1 #添加user用户并设置密码123.com
if [[ $? -eq 0 ]];then
echo “123.com” | passwd --stdin user > /dev/null 2>&1
sed -i “99 s/^/user ALL=(ALL) ALL/” /etc/sudoers
echo “Auth and add user. [ OK ]”
else
echo “User already exist! [Fail]”
fi
########## Shut root login ##########
sed -i “s/#PermitRootLogin yes/PermitRootLogin no/g” /etc/ssh/sshd_config
sed -i “s/#PermitEmptyPasswords no/PermitEmptyPasswords no/g” /etc/ssh/sshd_config
sed -i “s/#UseDNS yes/UseDNS no/g” /etc/ssh/sshd_config
echo “Shut root login. [ OK ]”
########## Forbidden not use serv