#!/bin/bash
function installopenssh() {
#### 请将此目录放到/opt目录下执行####
#### 配置YUM源####
clear
echo -e "\t\t########################"
echo -e "\t\t# 配置YUM仓库 #"
echo -e "\t\t########################"
sleep 1
echo -e "启动脚本....................................\033[32m [成功] \033[0m"
sleep 1
echo -e "备份YUM源中.................................\033[33m [稍等] \033[0m"
sleep 3
mkdir /etc/yum.repos.d/yum.bak &>/dev/null
mv /etc/yum.repos.d/* /etc/yum.repos.d/yum.bak/ &>/dev/null
id &>/dev/null
if [ $? -eq 0 ];then
echo -e "备份YUM源...................................\033[32m [成功] \033[0m"
else
echo -e "备份YUM源...................................\033[31m [失败] \033[0m"
fi
sleep 1
echo -e "配置YUM源中.................................\033[33m [稍等] \033[0m"
sleep 1
cat > /etc/yum.repos.d/local.repo <<EOF
[local]
name=localyum
baseurl=ftp://x.x.x.x/pub/centos7.5
enabled=1
gpgcheck=0
EOF
yum clean all &>/dev/null
if [ $? -eq 0 ];then
echo -e "配置YUM源...................................\033[32m [成功] \033[0m"
else
echo -e "配置YUM源...................................\033[31m [失败] \033[0m"
fi
#### 配置install openssh8.0 ####
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak &>/dev/null
echo -e "\t\t########################"
echo -e "\t\t# ssh文件备份完成 #"
echo -e "\t\t########################"
clear
echo -e "\t\t########################"
echo -e "\t\t# 配置安装openssh #"
echo -e "\t\t########################"
echo -e "安装依赖包....................................\033[33m [稍等] \033[0m"
RPMS='zlib-devel openssl-devel gcc perl-devel pam-devel unzip'
yum install -y $RPMS &>/dev/null
echo "openssh8.0默认路径为:/opt/openssh.install/RPM/openssh8.0"
echo "openssh8.6默认路径为:/opt/openssh.install/RPM/openssh8.6"
read -p "请输入存放RPM包绝对路径目录位置:" path
if [ -d $path ];then
echo -e "判断文件是否存在.......................... \033[032m [存在] \033[0m"
cd $path
yum -y install * &>/dev/null
if [ $? -eq 0 ];then
echo -e "安装成功...................................\033[032m [成功] \033[0m"
else
echo -e "安装失败...................................\033[031m [失败] \033[0m"
fi
else
echo -e "判断文件是否存在......................... \033[031m [不存在] \033[0m"
fi
sleep 2
#### 其他 配置####
clear
echo -e "\t\t########################"
echo -e "\t\t# 其他 配置 #"
echo -e "\t\t########################"
cd /etc/ssh/
chmod 400 ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key
if [ $? -eq 0 ];then
echo -e "调整权限....................................\033[032m [成功] \033[0m"
else
echo -e "调整权限....................................\033[031m [失败] \033[0m"
fi
sleep 2
clear
echo -e "\t\t########################"
echo -e "\t\t# 最后的配置 #"
echo -e "\t\t########################"
cat >> /etc/ssh/sshd_config <<EOF
PubkeyAuthentication yes
PasswordAuthentication yes
PermitRootLogin yes
EOF
sshd -t &>/dev/null
if [ $? -eq 0 ];then
read -p "完成所有配置是否重启sshd服务[Y/N]:" yn
if [ $yn == y ];then
systemctl restart sshd
sleep 2
if [ $? -eq 0 ];then
echo "[重启成功]"
else
echo "[重启失败]"
fi
elif [ $yn == n ];then
echo "[完成]没有重启sshd服务"
else
echo "[输入无效]"
fi
fi
sleep 2
clear
echo "SElinux开启状态会影响到root用户禁止远程登入状态"
read -p "是否关闭SElinux?[Y/N]:" yn2
if [ $yn2 == y ];then
setenforce 0
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
echo "[已关闭]"
elif [ $yn2 == n ];then
echo "[不进行操作]"
else
echo "[输入无效]"
fi
#### raw格式优化 ####
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak &>/dev/null
rm -rf /etc/ssh/sshd_config &>/dev/null
cp /opt/openssh.install/sshd_config /etc/ssh/ &>/dev/null
systemctl restart sshd &>/dev/null
}
#### 安装telnet ####
function telnet_install() {
yum -y localinstall /opt/openssh.install/telent/* &>/dev/null
cp telent/telnet /etc/xinetd.d/
mv /etc/securetty /etc/securetty.bak &>/dev/null
systemctl restart xinetd
#### firewalld ####
firewall-cmd --add-service=telnet --permanent &>/dev/null
firewall-cmd --reload &>/dev/null
}
#### 卸载telnet ####
function telnet_remove() {
rpm -e telnet-0.17-66.el7.x86_64
rpm -e telnet-server-0.17-66.el7.x86_64
firewall-cmd --remove-service=telnet --permanent
firewall-cmd --reload
mv /etc/securetty.bak /etc/securetty
mv /etc/xinetd.d/telnet /etc/xinetd.d/telnet.bak
}
## =====函数引用===== ##
installopenssh
#telnet_install
#telnet_remove
1qaz!QAZ