欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos7.5 一键初始化脚本

程序员文章站 2024-01-21 21:27:10
...

早在今年年初写过一个简单的初始化脚本,现在进行详细更新,具体如下


# !/bin/bash
# author : hobby
# Centos7.5  initializes the script

# 删除自带基础源
sudo rm -rf /etc/yum.repos.d/CentOS-*
# 获取阿里源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 清除原有yum源并重新生成缓存
sudo yum clean all && yum makecache


# 临时关闭及永久关闭selinux
sudo setenforce 0
sudo sed -i.ori 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# 关闭firewalld并去除开机自启
sudo systemctl stop firewalld && sudo systemctl disable firewalld

# 清除iptables所有规则
iptables -t nat -F
iptables -F


# 安装常用应用
sudo yum install -y epel-release netools vim lsof wget htop lrzsz 

# 添加自定义快捷键
sed -i "\$a alias c='clear'" ~/.bashrc
alias c='clear'

# 创建用户和密码
read -p "Do you wang to add user ? (please input y or n) " select
if [[ $select =~ "y" || $select =~ "Y" || $select =~ "yes" || $select =~ "YES" ]];then
	read -p "please setting username : " name
	echo -n "please setting passwd : "
	read -s  passwd

	adduser $name
    # 判断用户是否创建成功
	if [ $? -eq 0 ];then
	   echo "user ${name} is created successfully!!!"
	else
	   echo "user ${name} is created failly!!!"
	   exit 1
	fi

	echo $passwd | sudo passwd $name --stdin  &>/dev/null
	# 判断密码是否创建成功
	if [ $? -eq 0 ];then
	   echo "${name}'s password is set successfully"
	else
	   echo "${name}'s password is set failly!!!"
	fi
else
   break
fi

# 修改sudoer文件
sudo cat >>/etc/sudoers<<EOF
Runas_Alias    OP = root, daemon

Cmnd_Alias SYSTEM = /bin/rm -rf /, /bin/rm -rf *,  /bin/rm -rf ., /bin/rm -rf ./*, /bin/passwd, /sbin/reboot, /sbin/shutdown, /sbin/iptables, /bin/cat /etc/sudoers, /bin/vi /etc/sudoers, /bin/vim /etc/sudoers, /bin/vi /etc/passwd, /bin/vim /etc/passwd, /bin/cat /etc/passwd, /bin/vi /etc/shadow, /bin/vim /etc/shadow, /sbin/mkfs, /sbin/mkfs.ext2, /sbin/mkfs.ext3, /sbin/mkfs.ext4, /sbin/mkfs.xfs, /sbin/parted, /sbin/fdisk, /sbin/useradd, /sbin/adduser, /sbin/userdel, /bin/mv /*, /bin/mv /,  /sbin/groupadd, /sbin/groupdel, /sbin/chkconfig, /bin/mount, /bin/umount, /sbin/visudo, /bin/su, /bin/cat /etc/shadow, /usr/bin/chattr, /bin/super

root    ALL=(ALL)       ALL
admin   ALL= NOPASSWD: ALL, !SYSTEM

%operations     ALL=(OP) NOPASSWD: ALL, !SYSTEM
%developers     ALL=(OP) NOPASSWD: ALL, !SYSTEM

Cmnd_Alias OPS_SUDO = /bin/*,  /sbin/*,  /usr/bin/*,  /usr/sbin/*
ops ALL = (root) NOPASSWD: OPS_SUDO
dev ALL = (root)  NOPASSWD: OPS_SUDO
daemon ALL = (root) NOPASSWD: OPS_SUDO
EOF

echo "Initialization complete......"

 

相关标签: linux日常小操作