生产环境服务器安全扫描出OpenSSH漏洞问题,只能通过升级最新的OpenSSH版本解决。本文章适用于Centos7使用。
升级前先打开telnet或者vnc,否则升级失败。可能无法连接服务器。升级完成后记得关闭telnet或者vnc
安装相关依赖包
[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel pam* zlib*
-
从https://ftp.openssl.org/source/下载openssl,并上传至服务器
-
解压openssl
[root@localhost ~]# tar zxvf openssl-1.1.1l.tar.gz
- 检查环境
[root@localhost ~]# cd openssl-1.1.1l/
[root@localhost openssl-1.1.1l]# ./config --prefix=/usr/local/openssl
- 编译并安装
[root@localhost openssl-1.1.1l]# make && make install
- 替换当前系统的旧版本openssl(先保存原来的)
[root@localhost openssl-1.1.1l]# which openssl
/usr/bin/openssl
[root@localhost openssl-1.1.1l]# mv /usr/bin/openssl /usr/bin/openssl.old
[root@localhost openssl-1.1.1l]# mv /usr/lib64/openssl /usr/lib64/openssl.old
[root@localhost openssl-1.1.1l]# mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
[root@localhost openssl-1.1.1l]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1l]# ldconfig -v
- openssl安装完成,查看版本
[root@localhost openssl-1.1.1l]# openssl version
- 查看openssh版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
- 从https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/下载openssh,并上传至服务器
- 解压
[root@localhost ~]# tar zxvf openssh-8.8p1.tar.gz
- 移除旧版本
[root@localhost ~]# mv /etc/ssh /etc/ssh.old
- 编译并安装
[root@localhost ~]# cd openssh-8.8p1
[root@localhost openssh-8.8p1]# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening
[root@localhost openssh-8.8p1]# make && make install
- 修改启动脚本
#拷贝启动脚本
[root@localhost openssh-8.8p1]# cp ./contrib/redhat/sshd.init /etc/init.d/sshd
#修改启动脚本
[root@localhost openssh-8.8p1]# vim /etc/init.d/sshd
#按如下图修改,需要注意,此路径是你安装新版本的openssh路径,根据你的实际情况修改
SSHD=/usr/local/openssh/sbin/sshd
- 修改sshd配置文件/etc/ssh/sshd_config
#直接用root登录终端(此处根据自身情况考虑)
[root@localhost openssh-8.8p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
#设置是否允许X11转发
[root@localhost openssh-8.8p1]# echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
#是否允许密码验证
[root@localhost openssh-8.8p1]# echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
- 卸载原有ssh(先安装后卸载,也是怕升级失败)
[root@localhost openssh-8.8p1]# for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done
出现提示告警
将警告中被修改的文件名字再改回来
[root@localhost ~]# mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config
[root@localhost ~]# mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
[root@localhost ~]# mv /etc/ssh/moduli.rpmsave /etc/ssh/moduli
- 安装成功查看升级版本(如有报错,请检查环境变量)
[root@localhost ~]# ssh -V
- 查看sshd运行状态
systemctl status sshd
- 设置开机启动并启动
[root@localhost ~]# systemctl enable sshd --now
注意!!!升级前记得打开telnet或者vnc,否则升级失败会导致服务器SSH连接上不!!!
参考:
友人a笔记