前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1

Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1

作者头像
木子-Lee
发布2022-01-17 14:06:20
1.3K0
发布2022-01-17 14:06:20
举报

文章声明:此文基于木子实操撰写 生产环境:Rocky Linux release 8.3, Ubuntu 20.04.2 LTS, openssh-8.6p1 问题关键字:OpenSSH 升级, OpenSSH 更新, OpenSSH 漏洞修复


前述

OpenSSH(OpenBSD Secure Shell)是OpenBSD计划组的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。 OpenSSH 8.3p1及之前版本中scp的scp.c文件存在操作系统命令注入漏洞。该漏洞源于外部输入数据构造操作系统可执行命令过程中,网络系统或产品未正确过滤其中的特殊字符、命令等。攻击者可利用该漏洞执行非法操作系统命令。 详细参考国家信息安全漏洞库信息: CVE-2020-15778 目前Rocky Linux 8.3 RC1 采用的为OpenSSH_8.0p1,所以建议通过升级OpenSSH修复此问题。同样OpenSSH before 8.5也存在漏洞,所以建议修复至最新版本OpenSSH_8.6p1。 注:此操作步骤同样适用于Red Hat系所有7.x 8.x服务器系统。

Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1
Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1
Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1
Rocky Linux 8.3 RC1 OpenSSH升级至openssh-8.6p1

在升级之前,建议打开多个SSH终端连接,并安装telnet服务器,确保在SSH服务器升级异常时,可以通过telnet服务器远程连接,进行紧急问题修复处理。 Red Hat & CentOS 7.x 服务器上,只需要将dnf命令替换成yum命令即可。

Telnet服务器部署

代码语言:javascript
复制
# 安装telnet服务器
dnf install -y telnet-server
# 启动telnet服务器
systemctl start telnet.socket
# 配置防火墙,放行23端口
firewall-cmd --zone=public --permanent --add-port=23/tcp
# or (永久生效加 --permanent)
firewall-cmd --add-service=telnet --zone=public
# 重载防火墙配置
firewall-cmd --reload
# SELinux配置
semanage port -a -t telnetd_port_t -p tcp

升级OpenSSH

代码语言:javascript
复制
# 查看当前安装包
[root@localhost ~]# rpm -qa | grep openssh
openssh-clients-8.0p1-5.el8.x86_64
openssh-8.0p1-5.el8.x86_64
openssh-server-8.0p1-5.el8.x86_64

# 查看当前OpenSSH版本(Rocky Linux 默认使用OpenSSH 8.0p1)
[root@localhost ~]# ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1g FIPS  21 Apr 2020

# 备份现有SSH
[root@localhost ~]# mv /etc/ssh/ /etc/ssh.bak
[root@localhost ~]# mv /usr/bin/ssh /usr/bin/ssh.bak
[root@localhost ~]# mv /usr/sbin/sshd /usr/sbin/sshd.bak

# 如果您是第一次升级,备份/etc/init.d/sshd时会不存在,不影响后续操作
[root@localhost ~]# mv /etc/init.d/sshd /etc/init.d/sshd.bak
mv: 无法获取'/etc/init.d/sshd' 的文件状态(stat): No such file or directory

# 卸载现有OpenSSH
[root@localhost ~]# rpm -e --nodeps $(rpm -qa |grep openssh)
警告:文件 /etc/ssh/sshd_config:移除失败:No such file or directory
警告:文件 /etc/ssh/ssh_config.d/05-redhat.conf:移除失败:No such file or directory
警告:文件 /etc/ssh/ssh_config.d:移除失败:No such file or directory
警告:文件 /etc/ssh/ssh_config:移除失败:No such file or directory
警告:文件 /etc/ssh/moduli:移除失败:No such file or directory
警告:文件 /etc/ssh:移除失败:No such file or directory

# 确保已经卸载成功
[root@localhost ~]# rpm -qa | grep openssh

# 安装编译openssh所需要使用的包
[root@localhost ~]# dnf install wget gcc openssl-devel pam-devel rpm-build -y

# 下载OpenSSH二进制包
[root@localhost ~]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
[root@localhost ~]# tar -zxvf openssh-8.6p1.tar.gz
[root@localhost ~]# cd openssh-8.6p1

# 编译安装
[root@localhost openssh-8.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-ssl-dir=/usr/local/ssl --without-hardening
[root@localhost openssh-8.6p1]# make
[root@localhost openssh-8.6p1]# make install

# 授权
[root@localhost openssh-8.6p1]# chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key

# 复制配置文件
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

# 修改配置允许root用户远程登录
[root@localhost openssh-8.6p1]# echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# sed -i "s/^#Port/Port/g" /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# chmod 755 /etc/init.d/sshd

# 启用sshd,生成服务配置文件
[root@localhost openssh-8.6p1]# systemctl enable sshd
sshd.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable sshd

# 重启服务
[root@localhost openssh-8.6p1]# systemctl restart sshd

# 验证升级是否成功
[root@localhost ~]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1g FIPS  21 Apr 2020

禁用SCP与SFTP

有时候OpenSSH会出现一些其它漏洞,如OpenSSH 8.3p1及之前的版本,会存在scp漏洞等,建议禁用sftp及scp,详细操作如下:

代码语言:javascript
复制
# 禁用sftp
[root@localhost ~]# sed -i "s/^Subsystem/#Subsystem/g" /etc/ssh/sshd_config
# 确保sftp已经禁用
[root@localhost ~]# cat /etc/ssh/sshd_config | grep sftp
#Subsystem      sftp    /usr/libexec/sftp-server

# 因为禁用scp是一件麻烦的事情,可以直接删除scp命令或者重命名,相对来说更靠谱一些。
rm -rf /usr/bin/scp

# 重启sshd服务
[root@localhost openssh-8.6p1]# systemctl restart sshd

Ubuntu 服务器升级OpenSSH

因为木子刚好有Ubuntu 20.04.2 LTS服务器需要升级,所以这里将对应的升级方法一并提供。

代码语言:javascript
复制
# 下载OpenSSH二进制包
root@localhost:~# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
root@localhost:~# tar -zxvf openssh-8.6p1.tar.gz
root@localhost:~# cd openssh-8.6p1

# 编译安装
root@localhost:~# /configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-privsep-path=/var/lib/sshd
root@localhost:~# make
root@localhost:~# make install

# 重启服务
root@localhost:~# systemctl restart sshd

# 验证升级是否成功
root@localhost:~# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1f  31 Mar 2020

写在最后

最后再补上两句:安全无小事,防范是关键。安全无小事,责任大于天。 下篇预告:基于Rocky Linux 8.3 RC1搭建Rsync冷备容灾服务器,如果您有任何想学习了解的技术,欢迎在下方留言,木子将根据需求输出对应基础技术博文。

参考文献

[1] 国家信息安全漏洞库:http://www.cnnvd.org.cn/ [2] 腾讯安全:https://s.tencent.com/research/bsafe/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-05-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前述
  • Telnet服务器部署
  • 升级OpenSSH
  • 禁用SCP与SFTP
  • Ubuntu 服务器升级OpenSSH
  • 写在最后
  • 参考文献
相关产品与服务
脆弱性检测服务
脆弱性检测服务(Vulnerability detection Service,VDS)在理解客户实际需求的情况下,制定符合企业规模的漏洞扫描方案。通过漏洞扫描器对客户指定的计算机系统、网络组件、应用程序进行全面的漏洞检测服务,由腾讯云安全专家对扫描结果进行解读,为您提供专业的漏洞修复建议和指导服务,有效地降低企业资产安全风险。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档