弱弱的问一句,你们要求升级烦人的openssh了吗? -- linux 升级最新版 openssh-8.4p1

弱弱的问一句,你们要求升级烦人的openssh了吗?

分享个脚本,测试好使~

#!/bin/bash
#	author:wangxinyu
#	company:lx
#	version: v8.4
#	date: Fri Oct 16 18:16:23 CST 2020
#	state: Continuously updated
# 
# 使用前提 : 
# 1. 配置好yum源
# 2. 防止断连,开启telnet服务
# 3. 上传最新版的软件包

# 
#需要手动修改的变量
version="ssh_8.4" #定义版本号
soft_dir="opt" # 上传安装介质的目录
ssl_media="openssl-1.1.1h.tar.gz"  #软件包名
ssh_media="openssh-8.4p1.tar.gz" # 软件包名

#
ssl_soft="/$soft_dir/$ssl_media"
ssh_soft="/$soft_dir/$ssh_media"

#
if [ -f "${ssl_soft}" -a -f "${ssh_soft}" ];then
  filepath="/$soft_dir/$version" # 定义工作目录
  mkdir -p $filepath
else
  echo "`date +%H:%M:%S`--install media is not exist" |tee -a $filepath/check_point.log
  echo "`date +%H:%M:%S`--exitd" |tee -a ./check_point.log
  exit;
fi

#安装升级所需依赖包
function InstallDeploy(){
	echo "`date +%H:%M:%S`--install the Depend on the package.." |tee -a $filepath/check_point.log
	yum -y install gcc pam-devel zlib-devel perl openssl-devel
	echo "`date +%H:%M:%S`--install completed " |tee -a $filepath/check_point.log

}

#
function Unpack(){
	echo "`date +%H:%M:%S`--Unpack the package.... " |tee -a $filepath/check_point.log
	cd $filepath
	tar xvf /$soft_dir/openssl-1.1.1h.tar.gz
	tar xvf /$soft_dir/openssh-8.4p1.tar.gz
	echo "`date +%H:%M:%S`--Unpack completed " |tee -a $filepath/check_point.log
}

function Backup(){
	echo "`date +%H:%M:%S`--Backup important files..." |tee -a $filepath/check_point.log
	\cp -af  /usr/lib64/openssl /usr/lib64/openssl.old
	\cp -af  /usr/bin/openssl  /usr/bin/openssl.old
	\cp -af  /etc/pki/ca-trust/extracted/openssl  /etc/pki/ca-trust/extracted/openssl.old
	\cp -af  /usr/lib64/libcrypto.so.10  /usr/lib64/libcrypto.so.10.old
	\cp -af  /usr/lib64/libssl.so.10  /usr/lib64/libssl.so.10.old
	\cp -arf /etc/ssh/ /etc/ssh_`date +%F`	
	echo "`date +%H:%M:%S`--Backup completed " |tee -a $filepath/check_point.log
	
}

function Installopenssl(){
	echo "`date +%H:%M:%S`--Installopenssl...." |tee -a $filepath/check_point.log
	cd $filepath/openssl*/
	echo "`date +%H:%M:%S`--start to install openssl........." |tee -a $filepath/check_point.log
	./config --prefix=/usr/local --openssldir=/usr/local/openssl
  	make && make install &&
	# 加载动态库
	echo "/usr/local/lib64/" >> /etc/ld.so.conf
	ldconfig 
  	echo "`date +%H:%M:%S`--openssl upgrade complete..." |tee -a $filepath/check_point.log
	echo "`date +%H:%M:%S`--version: `openssl version`" |tee -a $filepath/check_point.log
	echo "`date +%H:%M:%S`--Installopenssl completed " |tee -a $filepath/check_point.log
}

function Installopenssh(){
	echo "`date +%H:%M:%S`--Installopenssh...." |tee -a $filepath/check_point.log	
	cd $filepath/openssh*/
	echo "`date +%H:%M:%S`--start to install openssh..." |tee -a $filepath/check_point.log
	./configure \
	--prefix=/usr \
	--sysconfdir=/etc/ssh \
	--with-md5-passwords \
	--with-pam \
	--with-tcp-wrappers \
	--with-ssl-dir=/usr/local/openssl \
	--with-zlib=/usr/local/lib64 \
	--without-hardening
  	make && 
	chmod 600 /etc/ssh/ssh_host*
	make install &&
	echo "`date +%H:%M:%S`--Installopenssh completed " |tee -a $filepath/check_point.log
}

function Configssh(){
	echo "`date +%H:%M:%S`--Config ssh...." |tee -a $filepath/check_point.log
	cd $filepath/openssh*/
	mv  /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/sshd.service_bk 
	cp contrib/redhat/sshd.init /etc/init.d/sshd
	chmod a+x /etc/init.d/sshd 
	cp contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
	chkconfig --add sshd
	chkconfig sshd on
	systemctl enable sshd
	echo "KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1" >> /etc/ssh/sshd_config 
	#sed -i 's/PermitRootLogin/#&/' /etc/ssh/sshd_config
	#echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
	echo "`date +%H:%M:%S`--Config ssh...."  |tee -a ./check_point.log
	echo "`date +%H:%M:%S`--Restart ssh service...." |tee -a $filepath/check_point.log
	systemctl restart sshd
	echo "`date +%H:%M:%S`--Restart ssh completed " |tee -a $filepath/check_point.log
	}

function start(){
	InstallDeploy
	Unpack
	Backup
	Installopenssl
	Installopenssh
	Configssh

	
}


start





… 有时间了整理 ansible 版本的~~

posted @ 2020-10-16 18:17  运维小九九  阅读(3)  评论(0编辑  收藏  举报