centos7.9 升级openssh到8.3以及openssl到1.1.1

2024-08-19 10:14:13 浏览数 (3)

先说两点注意:

1. 升级步骤简单整理为了脚本,脚本里没有过多的错误判断机制,适合对Linux shell有一定基础的人,基础薄弱的建议绕开。

2. 执行脚本前,对系统盘以及数据盘制作快照备份。升级出了错导致系统异常的,可以及时通过快照回滚恢复。不要指望阿里云或者腾讯云售后给你解决,人也不是你的运维。

下面为脚本内容,将脚本内容编辑到.sh 文件里,并赋予执行权限后运行,升级完成后重启验证。

如本次将脚本内容编辑到 test.sh中。再执行 chmod 777 test.sh 添加执行权限,最后执行 bash test.sh执行脚本来安装对应版本的openssl和openssh。

代码语言:bash复制
#!/bin/bash
cd /tmp
if [ $(id -u) != "0" ]; then
echo "error: Run as the root user"
exit 1
fi
openssh="openssh-8.3p1"
openssl="openssl-1.1.1g"
if [ ! -f ${openssh}.tar.gz ]
then
wget -c https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/${openssh}.tar.gz
fi
if [ ! -f ${openssl}.tar.gz ]
then
wget -c  https://www.openssl.org/source/${openssl}.tar.gz
fi
#安装依赖包
yum install -y telnet-server xinetd
yum install  -y gcc gcc-c   glibc make autoconf openssl openssl-devel pcre-devel  pam-devel
yum install  -y pam* zlib*
sleep 3
#备份
mkdir /tmp/ssh_backup/
cp /root/.ssh/authorized_keys /tmp/ssh_backup/
cp -r /etc/ssh/ /tmp/ssh_backup/
#安装openssl
tar xfz /tmp/openssl-1.1.1g.tar.gz
#备份Openssl
mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/include/openssl /usr/include/openssl_bak
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.bak
#安装OpenSSL
sleep 3
cd /tmp/openssl-1.1.1g
./config shared --prefix=/usr/local/openssl && make && make install
[ $? -eq 0 ] && echo "openssl安装成功"
ln -fs /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -fs /usr/local/openssl/include/openssl /usr/include/openssl
ln -fs /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
/sbin/ldconfig
echo "查看版本为: "
openssl version
echo "OpenSSL 升级完成,现在开始升级OPENSSH"
sleep 5
cd /tmp/
/usr/bin/tar -zxvf /tmp/openssh-8.3p1.tar.gz
cd /tmp/openssh-8.3p1
chown -R root.root /tmp/openssh-8.3p1
./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/openssl/include 
--with-ssl-dir=/usr/local/openssl   --with-zlib   --with-md5-passwords   --with-pam  && make && make install
cd /tmp/openssh-8.3p1
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.init /etc/rc.d/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod  x /etc/init.d/sshd
chmod  x /etc/rc.d/init.d/sshd
chkconfig --add sshd
chmod 600 /etc/ssh/ssh_host_ed25519_key
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
[ $? -eq 0 ] && echo "重启ssh中"
mv /usr/lib/systemd/system/sshd.service  /tmp/
sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config
systemctl enable sshd
systemctl daemon-reload
[ $? -eq 0 ] && echo "重启ssh中"
systemctl restart sshd.service
ssh -V
netstat -lntp
echo "OpenSSH版本已升级为8.3"
exit

0 人点赞