OpenAnolis8 (CentOS8) 升级OpenSSH9.9
公司漏扫,扫描出以下高危漏洞,经查需要升级openssh版本
OpenSSH 输入验证错误漏洞(CVE-2019-16905)
OpenSSH 操作系统命令注入漏洞(CVE-2020-15778)
OpenSSH 安全漏洞(CVE-2021-41617)
OpenSSH 代码问题漏洞(CVE-2023-38408)
OpenSSH 安全漏洞(CVE-2023-51385)
记录下升级步骤
一、下载OpenSSL和OpenSSH源码
Openssh下载地址
https://www.openssh.com/
Openssl下载地址
https://www.openssl.org/source
我这边的版本是
openssh-9.9p2
openssl-3.0.16
二、安装依赖
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel perl-IPC-Cmd perl-CPAN pam* zlib*
三、编译
编译OpenSSL
复制安装包到/usr/src/
tar -zxvf openssl-3.0.16.tar.gz
cd openssl-3.0.16
./config --prefix=/usr/local/openssl -d shared
make && make install
备份原始文件、新版本生效
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/openssl/include/openssl /usr/include/openssl
ln -sf /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib64" >> /etc/ld.so.conf
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
验证版本
# openssl version
OpenSSL 3.0.16 11 Feb 2025 (Library: OpenSSL 3.0.16 11 Feb 2025)
OpenSSL升级完成~
编译OpenSSH
复制安装包到/usr/src/
tar -zxvf openssh-9.9p2.tar.gz
cd openssh-9.9p2
chown -R root:root ./
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --without-openssl-header-check --with-pam --with-privsep-path=/var/lib/sshd --with-md5-passwords --with-zlib
make&& make install
证实版本
# /usr/local/openssh/bin/ssh -V
OpenSSH_9.9p2, OpenSSL 3.0.16 11 Feb 2025
卸载旧版本
service sshd stop
rpm -e `rpm -qa| grep openssh` --nodeps
cp -r /etc/ssh/ /etc/ssh_bak
yum remove -y openssh
rm -rf /etc/ssh/*
复制启动文件
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
复制可执行文件
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
允许root登录
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
重启sshd服务
/etc/init.d/sshd restart
查看服务运行状态
/etc/init.d/sshd status
添加开机启动
chkconfig --add sshd
查看升级后ssh版本
ssh -V
OpenSSH 升级完成~