首页 > 其他分享 >openssh 升级脚本

openssh 升级脚本

时间:2023-12-27 18:35:55浏览次数:34  
标签:脚本 33m sshd openssh echo 升级 file 033 0m

#!/bin/bash
#
#########################################################
# Function :openssh-9.6p1 openssl-1.1.1w update         #
# Platform :Centos7 redhat7.9                                    #
# Version  :2.2                                         #
# Date     :2023-12-19                                  #     
#########################################################
 
clear
export LANG="en_US.UTF-8"
 
#版本号
zlib_version="zlib-1.3"
openssl_version="openssl-1.1.1w"
openssh_version="openssh-9.6p1"


#安装包地址
file="/root/"
 
#默认编译路径
default="/usr/local" 
date_time=`date +%Y-%m-%d—%H:%M`
 
#安装目录
file_install="$file/openssh_install"
file_backup="$file/openssh_backup"
file_log="$file/openssh_log"
 
#源码包链接
zlib_download="http://www.zlib.net/$zlib_version.tar.gz"
openssl_download="https://mirrors.cloud.tencent.com/openssl/source/$openssl_version.tar.gz"
openssh_download="https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_version.tar.gz"
 
#开启telnet服务
yum install gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel zlib-devel tcp_wrappers-devel tcp_wrappers telnet-server -y 
firewall-cmd --add-port=23/tcp --permanent
firewall-cmd --reload
useradd light
echo "light" | passwd --stdin light
systemctl  start  telnet.socket
#暂停中,需要测试telnet的端口然后按任意键继续
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start...or Press Ctrl+c to cancel"
char=`get_char`
echo "继续执行..."

# Check if user is root
	if [ $(id -u) != "0" ]; then
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " 当前用户为普通用户,必须使用root用户运行,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 4
	exit
	fi
 
#判断是否安装wget
echo -e "\033[33m 正在安装Wget............... \033[0m"
sleep 2
echo ""
	if ! type wget >/dev/null 2>&1; then
		yum install -y wget
	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " wget已经安装了:" "\033[32m Please continue\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	fi
 
#判断是否安装tar
echo -e "\033[33m 正在安装TAR............... \033[0m"
sleep 2
echo ""
	if ! type tar >/dev/null 2>&1; then
		yum install -y tar
	else
	echo ""
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " tar已经安装了:" "\033[32m Please continue\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	fi
	echo ""
 
 
 
#创建文件(可修改)
mkdir -p $file_install
mkdir -p $file_backup
mkdir -p $file_log
mkdir -p $file_backup/zlib
mkdir -p $file_backup/ssl
mkdir -p $file_backup/ssh
mkdir -p $file_log/zlib
mkdir -p $file_log/ssl
mkdir -p $file_log/ssh
 
#备份文件(可修改)
cp -rf /usr/bin/openssl  $file_backup/ssl/openssl_$date_time.bak > /dev/null
cp -rf /etc/init.d/sshd  $file_backup/ssh/sshd_$date_time.bak > /dev/null
cp -rf /etc/ssh  $file_backup/ssh/ssh_$date_time.bak > /dev/null
cp -rf /usr/lib/systemd/system/sshd.service  $file_backup/ssh/sshd_$date_time.service.bak > /dev/null
cp -rf /etc/pam.d/sshd.pam  $file_backup/ssh/sshd_$date_time.pam.bak > /dev/null
 
##并卸载原有的openssh(可修改)
rpm -e --nodeps `rpm -qa | grep openssh`
 
#下载的源码包,检查是否解压(可修改)
#	if [ -e $file/$zlib_version.tar.gz ] && [ -e $file/$openssl_version.tar.gz ] && [ -e /$file/$openssh_version.tar.gz ];then
#		echo -e " 下载软件源码包已存在  " "\033[32m  Please continue\033[0m"
#	else
#		echo -e "\033[33m 未发现本地源码包,链接检查获取中........... \033[0m "
#	echo ""
#	cd $file
#	wget --no-check-certificate  $zlib_download
#	wget --no-check-certificate  $openssl_download
#	wget --no-check-certificate  $openssh_download
#	echo ""
#	fi
#zlib
echo -e "\033[33m 正在下载Zlib软件包.............. \033[0m"
sleep 2
echo ""
	if [ -e $file/$zlib_version.tar.gz ] ;then
		echo -e " 下载软件源码包已存在  " "\033[32m  Please continue\033[0m"
	else
		echo -e "\033[33m 未发现zlib本地源码包,链接检查获取中........... \033[0m "
	sleep 1
	echo ""
	cd $file
	wget --no-check-certificate  $zlib_download
	echo ""
	fi
#openssl
echo -e "\033[33m 正在下载Openssl软件包.............. \033[0m"
sleep 2
echo ""
	if  [ -e $file/$openssl_version.tar.gz ]  ;then
		echo -e " 下载软件源码包已存在  " "\033[32m  Please continue\033[0m"
	else
		echo -e "\033[33m 未发现openssl本地源码包,链接检查获取中........... \033[0m "
	echo ""
	sleep 1
	cd $file
	wget --no-check-certificate  $openssl_download
	echo ""
	fi
#openssh
echo -e "\033[33m 正在下载Openssh软件包.............. \033[0m"
sleep 2
echo ""
	if [ -e /$file/$openssh_version.tar.gz ];then
		echo -e " 下载软件源码包已存在  " "\033[32m  Please continue\033[0m"
	else
		echo -e "\033[33m 未发现openssh本地源码包,链接检查获取中........... \033[0m "
	echo ""
	sleep 1
	cd $file
	wget --no-check-certificate  $openssh_download
	echo ""
	fi
 
 
#安装zlib
#Install_zlib(){
echo -e "\033[33m 正在解压Zlib软件包.............. \033[0m"
sleep 2
echo ""
    cd $file && mkdir -p $file_install && tar -xzf zlib*.tar.gz -C $file_install
    if [ -d $file_install/$zilb_version ];then
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
              		echo -e "  zilb解压源码包成功" "\033[32m Success\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
        	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
              		echo -e "  zilb解压源码包失败,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
    echo ""
    sleep 4
    exit
    fi
echo -e "\033[33m 正在编译安装Zlib服务.............. \033[0m"
sleep 2
echo ""
    cd $file_install/zlib*
	./configure --prefix=$default/$zlib_version > $file_log/zlib/zlib_configure_$date_time.txt  #> /dev/null 2>&1
	if [ $? -eq 0 ];then
	echo -e "\033[33m make... \033[0m"
		make > /dev/null 2>&1
	echo $?
	echo -e "\033[33m make test... \033[0m"
		make test > /dev/null 2>&1
	echo $?
	echo -e "\033[33m make install... \033[0m"
		make install > /dev/null 2>&1
	echo $?
	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e "  编译安装压缩库失败,脚本退出中..." "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 4
	exit
	fi
 
	if [ -e $default/$zlib_version/lib/libz.so ];then
	sed -i '/zlib/'d /etc/ld.so.conf
	echo "$default/$zlib_version/lib" >> /etc/ld.so.conf
	echo ""
	echo "$default/$zlib_version/lib" >> /etc/ld.so.conf.d/zlib.conf
	ldconfig -v > $file_log/zlib/zlib_ldconfig_$date_time.txt > /dev/null 2>&1
	/sbin/ldconfig
	echo ""
	fi
#}
 
#install_openssl(){
echo -e "\033[33m 正在解压Openssl.............. \033[0m"
sleep 2
echo ""
    cd $file  &&  tar -xvzf openssl*.tar.gz -C $file_install
	if [ -d $file_install/$openssl_version ];then
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
              		echo -e "  OpenSSL解压源码包成功" "\033[32m Success\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
        	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
              		echo -e "  OpenSSL解压源码包失败,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
    echo ""
    sleep 4
    exit
    fi
	echo ""
echo -e "\033[33m 正在编译安装Openssl服务.............. \033[0m"
sleep 2
echo ""
    cd $file_install/$openssl_version
    ./config shared zlib --prefix=$default/$openssl_version >  $file_log/ssl/ssl_config_$date_time.txt  #> /dev/null 2>&1
	if [ $? -eq 0 ];then
	echo -e "\033[33m make clean... \033[0m"
		make clean > /dev/null 2>&1
	echo $?
	echo -e "\033[33m make -j 4... \033[0m"
		make -j 4 > /dev/null 2>&1
	echo $?
	echo -e "\033[33m make install... \033[0m"
		make install > /dev/null 2>&1
	echo $?
	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e "  编译安装OpenSSL失败,脚本退出中..." "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 4
	exit
	fi
 
	mv /usr/bin/openssl /usr/bin/openssl_$date_time.bak    #先备份
	if [ -e $default/$openssl_version/bin/openssl ];then
	sed -i '/openssl/'d /etc/ld.so.conf
	echo "$default/$openssl_version/lib" >> /etc/ld.so.conf
	ln -s $default/$openssl_version/bin/openssl /usr/bin/openssl
	ln -s $default/$openssl_version/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1 
    ln -s $default/$openssl_version/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 
	ldconfig -v > $file_log/ssl/ssl_ldconfig_$date_time.txt > /dev/null 2>&1
	/sbin/ldconfig
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " 编译安装OpenSSL " "\033[32m Success\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 4
	echo -e "\033[32m====================== OpenSSL veriosn =====================  \033[0m"
	echo ""
		openssl version -a
	echo ""
	echo -e "\033[32m=======================================================  \033[0m"
	else
	echo ""
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " OpenSSL软连接失败,脚本退出中..." "\033[31m  Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	fi
#}
 
#install_openssh(){
echo -e "\033[33m 正在解压Openssh.............. \033[0m"
sleep 2
echo ""
	cd $file && tar -xvzf openssh*.tar.gz -C $file_install
	if [ -d $file_install/$openssh_version ];then
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
         echo -e "  OpenSSh解压源码包成功" "\033[32m Success\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
        	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
         echo -e "  OpenSSh解压源码包失败,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
    echo ""
    sleep 4
    exit
    fi
	echo ""
echo -e "\033[33m 正在编译安装Openssh服务.............. \033[0m"
sleep 2
echo ""
	mv /etc/ssh /etc/ssh_$date_time.bak     #先备份
	cd $file_install/$openssh_version
	./configure --prefix=$default/$openssh_version --sysconfdir=/etc/ssh --with-ssl-dir=$default/$openssl_version --with-zlib=$default/$zlib_version >  $file_log/ssh/ssh_configure_$date_time.txt   #> /dev/null 2>&1
	if [ $? -eq 0 ];then
	echo -e "\033[33m make -j 4... \033[0m"
		make -j 4 > /dev/null 2>&1
	echo $?
	echo -e "\033[33m make install... \033[0m"
		make install > /dev/null 2>&1
	echo $?
	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " 编译安装OpenSSH失败,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 4
	exit
	fi
	
	echo ""
	echo -e "\033[32m==================== OpenSSH veriosn =================== \033[0m"
	echo ""
		/usr/local/$openssh_version/bin/ssh -V
	echo ""
	echo -e "\033[32m======================================================= \033[0m"
	echo ""
 
echo -e "\033[33m 正在迁移Openssh配置文件.............. \033[0m"
sleep 2
echo ""
#迁移sshd
	if [ -f  "/etc/init.d/sshd" ];then
		mv /etc/init.d/sshd /etc/init.d/sshd_$date_time.bak
	else
		echo -e " /etc/init.d/sshd不存在 " "\033[31m Not backed up(可忽略)\033[0m"
	fi
	cp -rf $file_install/$openssh_version/contrib/redhat/sshd.init /etc/init.d/sshd;
 
	chmod u+x /etc/init.d/sshd;
	chkconfig --add sshd      ##自启动
	chkconfig --list |grep sshd;
	chkconfig sshd on
#备份启动脚本,不一定有
	if [ -f  "/usr/lib/systemd/system/sshd.service" ];then
		mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service_bak
	else
		echo -e " sshd.service不存在" "\033[31m Not backed up(可忽略)\033[0m"
	fi
#备份复制sshd.pam文件
	if [ -f "/etc/pam.d/sshd.pam" ];then
		mv /etc/pam.d/sshd.pam /etc/pam.d/sshd.pam_$date_time.bak 
	else
        echo -e " sshd.pam不存在" "\033[31m Not backed up(可忽略)\033[0m"
	fi
	cp -rf $file_install/$openssh_version/contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
#迁移ssh_config	
	cp -rf $file_install/$openssh_version/sshd_config /etc/ssh/sshd_config
	sed -i 's/Subsystem/#Subsystem/g' /etc/ssh/sshd_config
	echo 'Subsystem sftp internal-sftp'>> /etc/ssh/sshd_config
	cp -rf $default/$openssh_version/sbin/sshd /usr/sbin/sshd
	cp -rf /$default/$openssh_version/bin/ssh /usr/bin/
	cp -rf $default/$openssh_version/bin/ssh-keygen /usr/bin/ssh-keygen
	sed -i 's/#PasswordAuthentication\ yes/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config
	#grep -v "[[:space:]]*#" /etc/ssh/sshd_config  |grep "PubkeyAuthentication yes"
	echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
 
#重启sshd
	service sshd start > /dev/null 2>&1
	if [ $? -eq 0 ];then
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " 启动OpenSSH服务成功" "\033[32m Success\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	echo ""
	sleep 2
	echo -e "\033[32m==================== OpenSSH veriosn =================== \033[0m"
	echo ""
		ssh -V
	echo ""
	echo -e "\033[32m======================================================== \033[0m"
	else
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
		echo -e " 启动OpenSSH服务失败,脚本退出中......" "\033[31m Error\033[0m"
	echo -e "\033[33m--------------------------------------------------------------- \033[0m"
	sleep 4
	exit
	fi
	echo ""
#}
 
#删除源码包(可修改)
#rm -rf $file/*.tar.gz
#rm -rf $file_install
 
##sshd状态
	echo ""
	echo -e "\033[33m输出sshd服务状态: \033[33m"
	sleep 1
	echo ""
	systemctl status sshd.service
	echo ""
	echo ""
	echo ""
	sleep 1
	
echo -e "\033[33m==================== OpenSSH file =================== \033[0m"
echo ""
	echo -e " Openssh升级安装目录请前往:  "
	cd  $file_install && pwd
	cd ~
	echo ""
	echo -e " Openssh升级备份目录请前往:  " 
	cd  $file_backup && pwd
	cd ~
	echo ""
	echo -e " Openssh升级日志目录请前往:  "
	cd  $file_log && pwd
	cd ~
	echo ""
echo -e "\033[33m======================================================= \033[0m"

 

标签:脚本,33m,sshd,openssh,echo,升级,file,033,0m
From: https://www.cnblogs.com/lightsoft2021/p/17931178.html

相关文章

  • nginx平衡升级在线升级
    nginx在线升级:nginx根据安装方式不同,升级方式也不同,一般有三种:yum方式安装,通过yum升级,不停机升级。编译方式安装,通过编译方式升级,不停机升级。容器方式安装,启动新容器方式升级,如果端口不变,需要停机,否则容器启动提示端口冲突。yum升级1、首选查看yum安装的nginx版本,nginx-V查看版本......
  • 相关业务SHELL脚本
    SHELL脚本:基于shell实现不同服务器root密码的统一遇到的问题:发现旧密码如果含有一些特殊符号,如"}","{"等,使用expect的话就会出现问题。#!/bin/bash#多个服务器修改密码的脚本file=./10-bt.txtnew_passwd='12\}2231321'whilereadippasswddoecho$passwdexpect......
  • 编译安装openssl-1.1.1和openssh-9.4
    1、安装openssl-1.1.1先处理下opensll的版本,以免编译安装Openssh环境异常:yumremoveopensslcd/optwgethttps://www.openssl.org/source/openssl-1.1.1n.tar.gztar-zxvfopenssl-1.1.1n.tar.gzcdopenssl-1.1.1n/./config--prefix=/opt/openssl#指定OpenSSL的......
  • nginx切割日志部署脚本编写
    #!/bin/bash#utf-8#description:部署nginx_lograte.sh脚本#---------------------------------------------------------------------script_name="logrotate_new.sh"script_download_directory="http://172.20.147.61/CentOS/app/script/hby"#......
  • Oracle 11g RAC(openfiler +multipath +udev +补丁升级)
    配套视频:《Oracle11gRAC安装》 或《Oracle11gRAC安装》配套文档:《一步一步在linux上部署Oracle11gR2RAC》......
  • CentOS7下快速升级至OpenSSH9.3p2安全版本
    之前的文章可供参考:CentOS7下快速升级OpenSSH至8.9p1安全版本一、CentOS7服务器上编译生成OpenSSH9.3p2的RPM包1、编译打包的shell脚本来源于该项目https://github.com/boypt/openssh-rpms复制(图片点击放大查看)unzipopenssh-rpms-main.zip-d/optcd/opt/cdop......
  • mongo升级服务,数据迁移迁移
    3*升级到5.*,会碰到索引不兼容问题 usestars_salesvarcollections=db.getCollectionNames();collections.forEach(function(collection){varindexes=db[collection].getIndexes();print("Indexesforcollection"+collection+":");printjson(......
  • springboot自动部署脚本
    #!/bin/sh##javaenvexportJAVA_HOME=/usr/local/jdk/jdk1.8.0_101exportJRE_HOME=$JAVA_HOME/jreAPI_NAME=apiJAR_NAME=$API_NAME\.jar#PID代表是PID文件PID=$API_NAME\.pid#使用说明,用来提示输入参数usage(){echo"Usage:sh执行脚本.sh[start|stop|re......
  • [升级] MySQL升级步骤及注意事项
    升级步骤a.备份数据库(包括schema,data,routines(function,triggersetc)b.修复util.checkForZSzerverUpgrade()发现的问题c.添加innodb_fast_shutdown=0来彻底的关闭mysqld.更新mysqlbinaries,可以使用tarball,RMP,mis等注意事项a.从5.7升级到8.0,或者在8.0.x之间升级可以......
  • JS逆向快速定位关键点之通用hook脚本
    大部分网站都会对关键参数进行加密,JS逆向时,我们首要任务是定位参数具体的加密逻辑。常见方式包含:关键字搜索、堆栈调试、XHR及事件监听、AST内存漫游、JSHook注入等本篇文章以JSHook注入为切入点,在做JS逆向往往需要定位到一些关键参数位置去分析,比如Cookie、Sign、Toke......