#!/bin/bash
#设置时区并同步时间
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if ! crontab -l |grep ntpdate &>/dev/null ; then
(echo "* 1 * * * ntpdate time.windows.com >/dev/null 2>&1";crontab -l) |crontab -l
fi
#更改字符集
#更改默认的ssh服务端口,禁止root用户远程连接,禁止空密码连接
/bin/cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
#sed -i ‘s/\#Port 22/Port 52113/‘ /etc/ssh/sshd_config
sed -i ‘s/\#PermitRootLogin yes/PermitRootLogin no/‘ /etc/ssh/sshd_config
sed -i ‘s/\#PermitEmptyPasswords no/PermitEmptyPasswords no/‘ /etc/ssh/sshd_config
sed -i ‘s/\#UseDNS yes/UseDNS no/‘ /etc/ssh/sshd_config
[ `grep "Port 52113" /etc/ssh/sshd_config |wc -l` -ne 0 -a `grep "PermitRootLogin no" /etc/ssh/sshd_config|wc -l` -ne 0 -a `grep "PermitEmptyPasswords no" /etc/ssh/sshd_config|wc -l` -ne 0 -a `grep "UseDNS no" /etc/ssh/sshd_config|wc -l` -ne 0 ] &&action "ssh set" /bin/true || action "ssh set" /bin/false
[ `grep "PermitRootLogin no" /etc/ssh/sshd_config|wc -l` -ne 0 -a `grep "PermitEmptyPasswords no" /etc/ssh/sshd_config|wc -l` -ne 0 -a `grep "UseDNS no" /etc/ssh/sshd_config|wc -l` -ne 0 ] &&action "ssh set" /bin/true || action "ssh set" /bin/false
#关闭防火墙:
systemctl disable firewalld.service
systemctl stop firewalld.service
#关闭selinux配置:
/usr/bin/cp /etc/selinux/config /etc/selinux/config.bak
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
#修改主机名:
read -p "请输入主机名" Hostname
hostname $Hostname
echo "HOSTNAME=$Hostname">/etc/sysconfig/network
#配置本地yum源
cd /etc/yum.repos.d/
tar -czvf repos.tar.gz *.repo
cat </etc/yum.repos.d/local.repo
[local]
name=CentOS7
baseurl=file:///mnt
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
mount /dev/sr0 /mnt
原文:https://www.cnblogs.com/xiaomabrother/p/12752310.html