本文章参考 https://blog.csdn.net/weixin_45409343/article/details/109613342
做了小改动
前期准备
cd /opt
#openssh 官网下载 最新版本8.4p1
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz
#openssl 官网下载最新版本
wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
# zlib 官网下载最新版本
wget http://www.zlib.net/zlib-1.2.11.tar.gz
cat openssh8.4_centos.sh
#脚本内容
#!/bin/bash
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}" ] && [ -f "${ssh_soft}" ];then
filepath="/$soft_dir/$version" # 定义工作目录
mkdir -p $filepath
else
echo "`date +%H:%M:%S`--升级所需安装包不存在,请检查。。。" |tee -a $filepath/check_point.log
echo "`date +%H:%M:%S`--安装已退出。。。" |tee -a $filepath/check_point.log
exit 1
fi
#安装升级所需依赖包
function InstallDeploy(){
# 对依赖包进行校验
lai=(gcc pam zlib perl openssl)
for install in ${lai[*]};do
b=$(rpm -qa | grep $install | wc -l)
if [ $b -lt 1 ];then
yum -y install $install
else
echo "`date +%H:%M:%S`--$install依赖已安装。。。跳过。。。" | tee -a $filepath/check_point.log
fi
done
# 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`--依赖安装结束,准备正式安装。。。 " |tee -a $filepath/check_point.log
}
#
function Unpack(){
echo "`date +%H:%M:%S`--解压安装包。。。 " |tee -a $filepath/check_point.log
cd $filepath
tar zxf /$soft_dir/openssl-1.1.1h.tar.gz
tar zxf /$soft_dir/openssh-8.4p1.tar.gz
echo "`date +%H:%M:%S`--解压完成。。。 " |tee -a $filepath/check_point.log
}
function Backup(){
echo "`date +%H:%M:%S`--重要动态库备份开始。。。。" |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` cd ..
echo "`date +%H:%M:%S`--备份完成。。。 " |tee -a $filepath/check_point.log
}
function Installopenssl(){
echo "`date +%H:%M:%S`--开始安装openssl。。。" |tee -a $filepath/check_point.log
cd $filepath/openssl*/
echo "`date +%H:%M:%S`--安装openssl进行中。。。。。。。" |tee -a $filepath/check_point.log
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make && make install &&
#创建软链接
#ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
#ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
# 加载动态库
echo "/usr/local/lib64/" >> /etc/ld.so.conf
ldconfig
echo "`date +%H:%M:%S`--openssl升级完成。。。。" |tee -a $filepath/check_point.log
}
function Installopenssh(){
echo "`date +%H:%M:%S`--开始安装openssh。。。" |tee -a $filepath/check_point.log
cd $filepath/openssh*/
echo "`date +%H:%M:%S`--安装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`--openssh升级完成。。。。" |tee -a $filepath/check_point.log
}
function Configssh(){
echo "`date +%H:%M:%S`--开始配置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
echo "`date +%H:%M:%S`--设置SSH开机自启。。。" |tee -a $filepath/check_point.log
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`--SSH服务重启中。。。。" |tee -a $filepath/check_point.log
systemctl restart sshd
}
function start(){
InstallDeploy
Unpack
Backup
Installopenssl
Installopenssh
Configssh
}
start
ssh -V && date
脚本执行后结果:
[root@centos2 update_openssh_centos]# ssh -V && date
OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020
Tue Nov 17 23:57:11 CST 2020
[root@centos2 update_openssh_centos]#