《Centos7.6之OpenSSH升级版本至8.6》



一、升级背景

通过绿盟漏洞扫描工具检测OpenSSH 安全漏洞CVE-2021-28041,现公司要求修复。
在这里插入图片描述
解决方法:openssh升级到openssh-8.6p1。


二、环境信息

操作系统:Centos7.6.1810
openssh:OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
openssl:OpenSSL 1.0.2k-fips 26 Jan 2017


三、注意事项

1、检查防火墙或selinux是否关闭。
2、更新前一定要多开1个或1个以上ssh终端,一旦更新失败当前shell终端是无法操作的,也就无法进行版本回退。
3、升级前一定要对ssh进行备份,避免更新失败时能回滚。
4、升级前一定要提前在测试环境验证,运行一段时间,确认没有问题才可在生产环境进行更新操作。
5、对于生产环境主机数量比较多时,建议先在1台或几台服务器上更新,运行一段时间,确认没有问题再执行批量更新操作。

总结:对于以上需要注意的内容,建议大家务必重视,小心谨慎总没错的。


四、升级步骤

# 1、升级准备
cd /opt && wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

# 2、安装依赖软件包
yum install gcc -y
yum install -y zlib-devel openssl-devel 
yum install pam-devel libselinux-devel zlib-devel openssl-devel -y

# 3、备份ssh(非常重要,请严格执行)
mv /etc/ssh /etc/ssh.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak

# 4、编译安装
cd /opt && tar -zxvf openssh-8.6p1.tar.gz
chown root.root /opt/openssh-8.6p1 -R
cd /opt/openssh-8.6p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam \
--with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl --without-hardening
make && make install

# 5、授权
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key

# 6、复制配置文件并设置允许root用户远程登录
cd /opt/openssh-8.6p1
cp -a contrib/redhat/sshd.init  /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod u+x /etc/init.d/sshd
mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service.bak

# 7、修改ssh配置
vim /etc/ssh/sshd_config 
PermitRootLogin yes
PasswordAuthentication yes
UseDNS no
UsePAM yes

# 8、设置开机自启
chkconfig --add sshd
chkconfig sshd on

# 9、重启ssh服务
systemctl daemon-reload
systemctl restart sshd

# 10、验证
[root@lvs-keepalived-02 ~]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.0.2k-fips  26 Jan 2017

如下图所示则表示编译成功
在这里插入图片描述


五、故障处理

现象:centos7升级ssh7.4到8.6版本后,ssh连接不稳定,时断时续,systemctl status sshd查看服务状态为activating(start),查看/var/log/message里不断提示sshd.service holdoff time over,scheduling restart

如下图所示:
在这里插入图片描述
原因:/usr/lib/systemd/system/sshd.service 与 systemd不兼容

处理办法:

[root@localhost ~]# cd /usr/lib/systemd/system 
[root@localhost system]# mv sshd.service sshd.service.bak  
[root@localhost system]# systemctl daemon-reload   

# 重启前执行
1、sshd -t 检查下配置有没有问题
2、/var/log/message里sshd有没有继续报错

# 以上正常后重启
systemctl restart sshd

如下图所示则表示服务正常
在这里插入图片描述


六、版本回退

回滚前:

[root@localhost etc]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.0.2k-fips  26 Jan 2017

回滚操作:

rm -rf /etc/ssh
mv /etc/ssh.bak /etc/ssh 
mv /usr/bin/ssh.bak /usr/bin/ssh 
mv /usr/sbin/sshd.bak /usr/sbin/sshd 
systemctl restart sshd

回滚后:

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

总结:整理不易,如果对你有帮助,可否点赞关注一下?

更多详细内容请参考:Linux运维实战总结

猜你喜欢

转载自blog.csdn.net/m0_37814112/article/details/116528466#comments_21685624