在CentOS7上升级OpenSSL3和 OpenSSH9.0p1

1.说明

CentOS7 自带的 OpenSSH 版本(OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26Jan 2017)漏扫出很多高
风险漏洞,预采用升级处理(升至 OpenSSH_9.0p1,OpenSSL 3.0.3 3 May 2022),而升级 OpenSSH
需先升级 OpenSSL(国际标准的加密及身份认证通信协议)。
通过绿盟漏洞扫描工具检测 OpenSSH 安全漏洞 CVE-2021-28041,现要求修复。

2.下载地址

OpenSSH下载地址:

https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz

OpenSSL下载地址:

https://www.openssl.org/source/openssl-3.0.3.tar.gz

3.升级OpenSSL

# 下载
wget https://www.openssl.org/source/openssl-3.0.3.tar.gz
# 解压缩
tar -zxvf openssl-3.0.3.tar.gz
# 配置
cd openssl-3.0.3
./config --prefix=/usr/ --openssldir=/usr/ shared
# 编译安装,需要一些时间我这里花了大概20分钟
make && make install
# 查看升级后的版本
openssl version -a

3.1.配置执行过程

# ./config --prefix=/usr/ --openssldir=/usr/ shared
Configuring OpenSSL version 3.0.3 for target linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Running configdata.pm
Creating Makefile.in
Creating Makefile
**********************************************************************
***                                ***
***  OpenSSL has been successfully configured           ***
***                                ***
***  If you encounter a problem while building, please open an  ***
***  issue on GitHub <https://github.com/openssl/openssl/issues> ***
***  and include the output from the following command:      ***
***                                ***
***    perl configdata.pm --dump                ***
***                                ***
***  (If you are new to OpenSSL, you might want to consult the  ***
***  'Troubleshooting' section in the INSTALL.md file first)   ***
***                                ***
**********************************************************************

3.2.版本信息

OpenSSL 3.0.3 3 May 2022 (Library: OpenSSL 3.0.3 3 May 2022)
built on: Tue Jun 21 01:33:10 2022 UTC
platform: linux-x86_64
options: bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -
DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -
DNDEBUG
OPENSSLDIR: "/usr/"
ENGINESDIR: "/usr//lib64/engines-3"
MODULESDIR: "/usr//lib64/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_ia32cap=0xfffa32035f8bffff:0xd01e4fbb

4.升级OpenSSH

4.1.安装 telnet 服务

yum -y install telnet-server

4.2.使用 telnet 连接

1.启动telent服务

#启动 telnet 服务
systemctl start telnet.socket

2.添加pts终端入口
如果要使用root用户登录,也是需要在/etc/securetty文件中添加pts终端入口的(pts/0代表登陆的终端第
一个,pts/1代表第二个)
vim /etc/securetty

pts/0
pts/1

若 ssh 中断可采用 telnet 进行远程控制,进行处理 ssh 升级

telnet [服务器 ip]

4.3.安装相关命令依赖

yum install -y pam* zlib*

4.4.备份原 ssh 配置

mv /etc/ssh /etc/ssh_bak

4.5.停止并卸载原有的 OpenSSH

#停止 ssh 服务
systemctl stop sshd
#查看安装的 ssh
rpm -qa | grep openssh
#卸载 rpm 安装的 ssh
yum remove openssh*
yum remove -y openssh-clients-7.4p1-22.el7_9.x86_64
yum remove -y openssh-7.4p1-22.el7_9.x86_64
yum remove -y openssh-server-7.4p1-22.el7_9.x86_64

4.6.安装 OpenSSH

#安装 OpenSSH
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
#解压缩
tar -xzvf openssh-9.0p1.tar.gz
#配置
cd openssh-9.0p1
./configure --with-zlib --with-ssl-dir --with-pam \
--bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc/ssh
#编译安装
make && make install
cp contrib/redhat/sshd.init /etc/init.d/sshd
#查看升级后的 ssh 版本
ssh -V

4.7.修改 ssh 配置文件

默认 ssh 不允许 root 登录系统,如果想要 root 登录需要修改 ssh 配置文件,将#PermitRootLogin
prohibit-password 参数改成 PermitRootLogin yes并取消注释,开启 root 权限登录 。

vim /etc/ssh/sshd_config

...
PermitRootLogin yes
...

4.8.关闭 selinux

#修改 selinux 配置参数,永久关闭 selinux(重启后生效),也可vi /etc/selinux/config 手动修sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#临时关闭 selinux(使当前系统立即生效)
setenforce 0
#查看状态
getenforce

4.9.重启 OpenSSH

#重启 OpenSSH
service sshd restart
systemctl restart sshd

4.10.卸载 telnet

#卸载 telnet 服务
yum remove -y telnet-server
# 去除之前添加的pts/0和pts/1
vim /etc/securetty

到此结束。

猜你喜欢

转载自blog.csdn.net/somken/article/details/130200624