升级openssh,是在做等保测评时,被漏洞扫描如下2个问题,要求必须解决。
OpenSSH 输入验证错误漏洞(CVE-2019-16905)
OpenSSH 安全漏洞(CVE-2021-28041)
  由于操作系统是CentOS 8.2,网上的文档几乎都要求先升级openssl,再升级openssh。但是,我按照这个顺序,编译安装升级openssl过程中有报错,编译安装升级openssh后,使用ssh重新远程连接就不能用了。
  试了2份文档,这个流程都不行。
  观察发现CentOS 8的openssl版本并不低,至少比网上的文档要高一些。
  于是,我只编译安装升级了openssh。在昨天的重新漏洞扫描后,上面的2个漏洞都没有了。

  真心建议:凡是编译安装,如果是云服务器,最好先做“快照”。这点费用值得!

 

安装telnet
  避免ssh升级失败,无法使用ssh远程登录服务器。

[root@ALI-JumpServer ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
yum -y install telnet-server.x86_64
yum list | grep telnet-server
yum -y install xinetd
yum list | grep xinetd

配置开机自启动

systemctl enable telnet.socket
systemctl enable xinetd

启动telnet服务

systemctl start telnet.socket
systemctl start xinetd

查看23端口是否启动

netstat -lntup

在配置文件增加如下2行内容

[root@ALI-JumpServer ~]# cat /etc/securetty
pts/0
pts/1

可以使用“命令提示符”执行命令测试telnet能否登录到服务器:

C:\Users\少荃>telnet 10.0.0.69

 

下载openssh源码包

cd /usr/local/src/
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

解压

tar xvf openssh-8.6p1.tar.gz

编译

cd openssh-8.6p1/

  经过多次编译失败的日志,补充yum安装缺失的安装包。

yum install zlib* -y
yum install -y libcry*
yum install -y openssl-devel
yum -y install pam-devel
./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
echo $?

安装

make
echo $?

  安装过程中报错,发现需要做如下授权。

chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key

  安装过程中提示文件已存在,做备份处理。

mv /etc/ssh/ssh_config /etc/ssh/ssh_config.ori
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
mv /etc/ssh/moduli /etc/ssh/moduli.ori
make install
echo $?

修改ssh配置文件

[ydt@ALI-JumpServer ~]$ grep "^Permit" /etc/ssh/sshd_config
PermitRootLogin yes
[ydt@ALI-JumpServer ~]$ grep "DNS" /etc/ssh/sshd_config
UseDNS no

复制文件到系统服务目录

cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

检查启动ssh服务的文件是否有可执行权限

ll /etc/init.d/sshd

配置ssh服务开机自启动

[root@bogon openssh-8.6p1]# chkconfig --add sshd
[root@bogon openssh-8.6p1]# systemctl enable sshd
Synchronizing state of sshd.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable sshd
[root@bogon openssh-8.6p1]# /usr/lib/systemd/systemd-sysv-install enable sshd
[root@bogon openssh-8.6p1]# systemctl enable sshd
Synchronizing state of sshd.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable sshd

移走原来的服务,否则,可能重启ssh失败

mv /usr/lib/systemd/system/sshd.service /home/

启动ssh服务

[root@bogon openssh-8.6p1]# /etc/init.d/sshd restart
Reloading systemd:                                         [  OK  ]
Restarting sshd (via systemctl):                           [  OK  ]
[root@bogon openssh-8.6p1]# netstat -lntup|grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      110173/sshd: /usr/s 
tcp6       0      0 :::22                   :::*                    LISTEN      110173/sshd: /usr/s 
tcp6       0      0 :::2222                 :::*                    LISTEN      1961/docker-proxy

查看ssh版本号

[root@bogon openssh-8.6p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1g FIPS  21 Apr 2020

 

  升级openssh版本后,使用SecureCRT连接可能会失败,好像是加密算法升级了。可以使用SecureCRT 8以上的版本,或者在配置文件增加以下配置:

[root@ALI-JumpServer ~]# tail -1 /etc/ssh/sshd_config
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org

  重启ssh服务即可。

 

  参考资料:https://blog.csdn.net/lhrm0213/article/details/117565350——OpenSSH 安全漏洞(CVE-2021-28041)修复(升级OpenSSH至最新版本(8.6p1))