0


记一次修复漏洞(OpenSSH 安全漏洞(CVE-2023-28531))CentOS升级openssh

1.查看当前openssl和openssh版本
openssl version -a
ssh -V
2.安装并启用telnet服务(防止升级过程无法连接机器)
yum -y install telnet-server xinetd
设置开机自启
systemctl enable xinetd.service
systemctl enable telnet.socket
启动服务
systemctl start telnet.socket
systemctl start xinetd
3.配置防火墙
法一:直接对外开发23端口(高风险)

#--permanent 为永久开启,不加此参数重启防火墙后规则不保存
firewall-cmd --add-port=23/tcp --permanent

#重启防火墙
firewall-cmd --reload

法二:指定IP开放

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.66.9.1 port protocol=tcp port=23 accept'
firewall-cmd --reload

4.允许root远程登录
修改/etc/securetty文件,在末尾添加

#不一定就是这个,有可能是pts/0或者pts/1,其他可查log
pts/4
5.重启telnet服务和守护进程
systemctl restart telnet.socket
systemctl restart xinetd.service
6.测试通过telnet登录服务器
7.升级openssl(3.0.7)
#下载、解压安装包
wget http://www.openssl.org/source/old/3.0/openssl-3.0.7.tar.gz --no-check-certificate
tar -zxvf openssl-3.0.7.tar.gz
cd openssl-3.0.7

#安装依赖
yum install -y gcc gcc-c++ glibc make automake autoconf pam pam-devel zlib zlib-devel
#编译预配置
./config shared --prefix=/usr/local/openssl

#编译安装
make && make install
###老版本可备份也可不备份
#备份老版本openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak

#软连接刚编译好的新版本openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl

#配置库文件路径

#注意检查左边的路径下确有.so文件
echo '/usr/local/openssl/lib64' > /etc/ld.so.conf.d/openssl-x86_64.conf
#使配置生效
ldconfig -v
8.升级openssh至9.3
#下载、解压安装包
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
tar -zxvf openssh-9.3p1.tar.gz
#更改用户组和所有者
chown -R root.root ./openssh-9.3p1

#停止当前ssh服务,停止前确保telnet可连接
systemctl stop sshd
#删除老配置
rm -rf /etc/ssh/*

#卸载已安装的openssh相关软件包
rpm -e rpm -qa | grep openssh --nodeps

#编译预配置
cd openssh-9.3p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-zlib --with-ssl-dir=/usr/local/openssl/include/openssl --with-md5-passwords --with-pam

#编译安装
make && make install

#检查并删除老版本启动脚本
ls /usr/lib/systemd/system/ssh*
rm -f /usr/lib/systemd/system/ssh*

#建立软连接
ln -s /usr/local/openssh/sbin/sshd /usr/sbin/
ln -s /usr/local/openssh/bin/* /usr/bin/

#重新加载系统管理守护进程(systemd) 的配置文件

systemctl daemon-reload

#启动并设置开机自启动
systemctl start sshd && systemctl enable sshd
#允许root远程登录
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
#重启ssh服务
systemctl restart sshd
#查看openssh版本,验证是否升级成功
ssh -V

#关闭telnet服务,先测试ssh是否可连接
systemctl stop telnet.socket
systemctl disable telnet.socket

#删除防火墙放行端口
firewall-cmd --remove-port=23/tcp --permanent
firewall-cmd --reload

9.编译安装openssh---(报错集合)
如果报错:
configure: error: *** zlib.h missing - please install first or check config.log ***
需要安装zlib-devel
[root@bo-gon openssh-9.3p1]# yum install -y zlib-devel

如果报错:
configure: error: *** OpenSSL headers missing - please install first or check config.log ***
configure: error: *** working libcrypto not found, check config.log
需要安装openssl-devel包
[root@bo-gon openssh-9.3p1]# yum -y install openssl-devel

如果报错:
checking whether OpenSSL's headers match the library... no
configure: error: Your OpenSSL headers do not match your
library. Check config.log for details.
If you are sure your installation is consistent, you can disable the check
by running "./configure --without-openssl-header-check".
Also see contrib/findssl.sh for help identifying header/library mismatches.

添加--without-openssl-header-check参数继续编译
./configure --prefix=/usr --sysconfdir=/etc/ssh --without-openssl-header-check

解决完报错后重新执行 ./configure --prefix=/usr --sysconfdir=/etc/ssh
完成后执行make && makeinstall

标签: centos 服务器 linux

本文转载自: https://blog.csdn.net/DDDM456/article/details/130015753
版权归原作者 Vacancy空白 所有, 如有侵权,请联系我们删除。

“记一次修复漏洞(OpenSSH 安全漏洞(CVE-2023-28531))CentOS升级openssh”的评论:

还没有评论