这篇文章上次修改于 612 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

OpenSSH 安全漏洞(CVE-2021-28041)为高危漏洞,漏洞ID为SF-0005-06510,危害影响OpenSSH:8.5以下版本,CNNVD编号CNNVD-202103-527,最佳处理方式为更新OpenSSH版本(就更新OpenSSH版本为8.6p1进行步骤说明)。
CentOS7.9原ssh版本为OpenSSH_7.4p1:

[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

安装前置依赖:

yum install gcc glibc zlib zlib-devel openssl openssl-devel pam-devel -y

卸载openSSH:

# 注意,这里进行卸载之前需确保还有其他方式连接到服务器,若卸载完成后服务器发生断连将无法再次连接,可安装telnet或VNC之类的服务防止失联
yum remove openssh

安装OpenSSH_8.6p1

# 下载安装包
wget https://src.fedoraproject.org/repo/pkgs/openssh/openssh-8.6p1.tar.gz/sha512/9854eda0b773c64c9f1f74844ce466b2b42ee8845f58ad062b73141d617af944fa4ebafdf72069f400106d2c2bd0a69c92fe805ec1fc26d4f0faadf06c3fbbe6/openssh-8.6p1.tar.gz
tar -zxvf openssh-8.6p1.tar.gz
cd openssh-8.6p1
# 预编译
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/lib64 --without-hardening
# 编译
make
# 安装前最好删除一下旧密钥对
rm -f /etc/ssh/ssh_host_*
# 安装
make install
# 配置文件修改参数
vim /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
PID_FILE=/run/sshd.pid
# 编辑以上字段并取消注释
# 启动ssh
systemctl start sshd
# 此时可能依然会出现无法连接的情况,查看日志
error: Could not get shadow information for root
# 此问题为SELinux问题,可将SELinux调整为disable或permissive状态
# 临时关闭SELinux
setenforce 0
# 修改SELinux配置(永久有效)
vim /etc/selinux/config
SELINUX=permissive
# 将SELINUX项的值改为permissive或disable
# 临时关闭后SSH可进行连接
# 将ssh设定为开机启动
systemctl enable sshd
# 重启服务器,使SELinux配置生效
reboot
# 重启完成后,连接ssh查看版本
[root@localhost ~]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.0.2k-fips  26 Jan 2017