OpenSSL和OpenSSH这两个难兄难弟可谓是Linux系统漏洞最高发的组件,每年都有大量漏洞被发现,频繁升级更新真是让运维人员不厌其烦。这不本人前段时间才把十几台服务器升级到最新版OpenSSH9.3p1,这两天又曝出高危漏洞CVE-2023-38408,偏偏这两货都是系统最重要的组件,你还不能忽视它们漏洞的存在(真心怀疑代码质量不咋滴,建议作者还是彻底回炉重造的好^_^)。 闲话休提,上代码
升级OpenSSL
先到官网下载升级包(
https://www.openssl.org/source/),以下是openssl-1.1.1q的升级脚本,其他版本换个包名就行:
#!/bin/bash
set -e
#安装依赖包,如果确认已经安装过的可以去掉
yum install -y gcc gcc-c++ autoconf automake zlib-devel pcre-devel
# 脚本与安装包在同一目录
tar -xzf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/openssl --openssldir=/etc/ssl --shared zlib
make
make install
#更新系统库
sudo echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/openssl.conf
sudo ldconfig
mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
openssl version
升级OpenSSH
OpenSSH官网国内下载非常慢,所以这里推荐到阿里云的镜像官网下载:
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/
#!/bin/bash
set -e
#安装依赖
yum install -y wget gcc pam-devel libselinux-devel zlib-devel openssl-devel
#备份原配置文件
cp /etc/ssh/sshd_config sshd_config.bak
cp /etc/pam.d/sshd sshd.bak
tar -xzf openssh-9.3p1.tar.gz
cd openssh-9.3p1
#pam不指定可以不装,ssl-dir指定openssl的源码目录
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-zlib --with-pam --with-ssl-dir=/usr/local/openssl
make
make install
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
chmod 600 /etc/ssh/ssh_host_rsa_key
#重建个服务,如果使用原服务可能会遇到服务一直无法启动问题
if test -e /lib/systemd/system/sshd.service
then
mv /lib/systemd/system/sshd.service /lib/systemd/system/sshd.service.bak
fi
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
chmod u+x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
#重启
systemctl daemon-reload
systemctl restart sshd
#查看新版本
ssh -V
问题1:
提示:configure: error: *** working libcrypto not found,是缺少openssl-devel包
问题2:
ssh -V显示的openssl版本与openssl version版本不一致,这是因为在编译openssh时指定的ssl版本与系统openssl不同,其实问题不大,如果你有强迫症只能重新编译一次,指定正确的ssl路径了
问题3:
如果以前版本是RPM安装的可以删除,rpm -e --nodeps `rpm -qa | grep openssh`
--------------
有脚本需要的可以到我git仓库下载,里面还有一些常用脚本
https://gitee.com/jqncc/py-ops-scripts/tree/master/shell