Centos 8 离线升级openssh 9.9

背景

复制代码
  根据云服务漏检报告,需要升级云服务器openssh服务(离线环境)。
  本文将采用rpm包形式,将openssh服务由OpenSSH_8.0p1 升级至OpenSSH_9.9p1。
  准备一台能够联网的服务器(简称server1)用于下载程序包,便于云服务器更新。

准备升级包

1. 查看云服务器服务器当前openssh版本

bash 复制代码
#查看系统版本
[root@centos8 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
#查看openssh服务版本
[root@centos8 ~]# ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1k  FIPS 25 Mar 2021

2. 下载安装telnet

bash 复制代码
登录server1
mkdir /telnet;cd /telnet
[root@centos8 telnet]# yum install  --downloadonly --downloaddir=/telnet  xinetd* telnet-server* telnet* -y
Repository base is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
上次元数据过期检查:1:17:45 前,执行于 2025年02月05日 星期三 00时46分19秒。
依赖关系解决。
=============================================================================================================================================================
 软件包                                 架构                            版本                                        仓库                                大小
=============================================================================================================================================================
安装:
 telnet                                 x86_64                          1:0.17-76.el8                               AppStream                           72 k
 telnet-server                          x86_64                          1:0.17-76.el8                               AppStream                           48 k
 xinetd                                 x86_64                          2:2.3.15-24.el8                             AppStream                          135 k

事务概要
=============================================================================================================================================================
安装  3 软件包

总下载:255 k
安装大小:555 k
YUM将仅会从事务下载软件包。
下载软件包:
(1/3): telnet-server-0.17-76.el8.x86_64.rpm                                                                                  3.2 kB/s |  48 kB     00:14
(2/3): xinetd-2.3.15-24.el8.x86_64.rpm                                                                                       9.0 kB/s | 135 kB     00:14
(3/3): telnet-0.17-76.el8.x86_64.rpm                                                                                         4.8 kB/s |  72 kB     00:14
-------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                          17 kB/s | 255 kB     00:14
完毕!
下载的软件包保存在缓存中,直到下次成功执行事务。
您可以通过执行 'yum clean packages' 删除软件包缓存。
[root@centos8 telnet]# ls
telnet-0.17-76.el8.x86_64.rpm  telnet-server-0.17-76.el8.x86_64.rpm  xinetd-2.3.15-24.el8.x86_64.rpm

3. 下载openssh 9.9 rpm包

bash 复制代码
登录 server1
mkdir  openssh;cd openssh
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-clients-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-clients-debuginfo-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-debuginfo-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-debugsource-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-server-9.9p1-1.el8.x86_64.rpm
wget http://down.tag.gg/Openssh/rpm/el8/openssh-9.9-openssl-3.4.0/openssh-server-debuginfo-9.9p1-1.el8.x86_64.rpm

[root@centos8 openssh]# ls
openssh-9.9p1-1.el8.x86_64.rpm                    openssh-debuginfo-9.9p1-1.el8.x86_64.rpm    openssh-server-debuginfo-9.9p1-1.el8.x86_64.rpm
openssh-clients-9.9p1-1.el8.x86_64.rpm            openssh-debugsource-9.9p1-1.el8.x86_64.rpm
openssh-clients-debuginfo-9.9p1-1.el8.x86_64.rpm  openssh-server-9.9p1-1.el8.x86_64.rpm

4. 打包

bash 复制代码
 cd /
 tar -zcvf update_ssh_9.9.tgz /telnet /openssh 

升级云服务器openssh

1. 上传及解压压缩包

bash 复制代码
scp update_ssh_9.9.tgz root@x.x.x.x:/
登录云服务器
tar -zxvf update_ssh_9.9.tgz

2. 安装telnet (防止openssh升级失败无法登录云服务器)

bash 复制代码
cd /telnet
rpm -Uvh *.rpm --nodeps --force
systemctl start telnet.socket
systemctl start  xinetd
echo 'pts/0' >>/etc/securetty
echo 'pts/1' >>/etc/securetty
systemctl restart telnet.socket
telnet 云服务ip

3.安装 openssh

bash 复制代码
1)备份原来ssh相关配置文件
cp -rp /etc/ssh /etc/ssh-bak

2)卸载老版本的openssh (不要断开终端,不然无法远程连接)
rpm -qa | grep openssh | xargs rpm -e --nodeps

3)安装新版本:安装后执行命令 ssh -V 查看新的版本。
cd /openssh
rpm -Uvh openssh-*.rpm
[root@centos8 openssh]# rpm -Uvh openssh-*.rpm
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:openssh-debugsource-9.9p1-1.el8  ################################# [ 14%]
   2:openssh-debuginfo-9.9p1-1.el8    ################################# [ 29%]
   3:openssh-9.9p1-1.el8              ################################# [ 43%]
   4:openssh-clients-9.9p1-1.el8      ################################# [ 57%]
   5:openssh-server-9.9p1-1.el8       ################################# [ 71%]
   6:openssh-clients-debuginfo-9.9p1-1################################# [ 86%]
   7:openssh-server-debuginfo-9.9p1-1.################################# [100%]


4)设置ssh配置文件权限:
chmod -v 600 /etc/ssh/ssh_host_*_key
mode of '/etc/ssh/ssh_host_ecdsa_key' changed from 0640 (rw-r-----) to 0600 (rw-------)
mode of '/etc/ssh/ssh_host_ed25519_key' changed from 0640 (rw-r-----) to 0600 (rw-------)
mode of '/etc/ssh/ssh_host_rsa_key' changed from 0640 (rw-r-----) to 0600 (rw-------)

5)执行如下命令检测配置文件是否正常
sshd -t
说明:若检测提示"UsePrivilegeSeparation"相关报错,则执行如下命令在检测。
sudo sed -i '/UsePrivilegeSeparation/s/^/#/' /etc/ssh/sshd_config

6)检测配置文件没问题后再考虑重启sshd服务。
重启ssh服务
[root@centos8 openssh]# systemctl restart sshd;systemctl status sshd
● sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd; generated)
   Active: active (running) since Wed 2025-02-05 02:24:35 EST; 9ms ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2486 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS)
  Process: 2495 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
 Main PID: 2505 (sshd)
    Tasks: 1 (limit: 25358)
   Memory: 1.3M
   CGroup: /system.slice/sshd.service
           └─2505 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups

2月 05 02:24:35 centos8 systemd[1]: Stopped SYSV: OpenSSH server daemon.
2月 05 02:24:35 centos8 systemd[1]: Starting SYSV: OpenSSH server daemon...
2月 05 02:24:35 centos8 sshd[2495]: /sbin/restorecon: lstat(/etc/ssh/ssh_host_dsa_key.pub) failed: No such file or directory
2月 05 02:24:35 centos8 sshd[2505]: Server listening on 0.0.0.0 port 22.
2月 05 02:24:35 centos8 sshd[2505]: Server listening on :: port 22.
2月 05 02:24:35 centos8 sshd[2495]: Starting sshd:[  确定  ]
2月 05 02:24:35 centos8 systemd[1]: Started SYSV: OpenSSH server daemon.
查看ssh版本:
[root@centos8 openssh]# ssh -V
OpenSSH_9.9p1, OpenSSL 3.4.0 22 Oct 2024
到此升级成功

4. 关闭telnet

bash 复制代码
openssh升级成功后,telnet 可以关闭,
systemctl stop telnet.socket 
systemctl disable telnet.socket

参考链接

https://blog.tag.gg/showinfo-3-36360-0.html

相关推荐
wb1896 分钟前
docker-ce容器技术重习
运维·笔记·docker·容器·云计算
jiayong236 分钟前
第 4 课:怎么把一个大页面拆成多个组件
运维·服务器·前端
qq_8573058199 分钟前
ubuntu 22 源码安装bochs
linux·运维·ubuntu
A-刘晨阳9 分钟前
麒麟v10桌面版2403版本运行程序提示权限不足(KYSEC)
运维·云计算·操作系统·银河麒麟·麒麟桌面系统
Zhu75810 分钟前
【软件更新】在Ubuntu24 LTS中更新openssl到指定版本,例如openssl3.5.6 LTS
linux·ssh·ssl
ALINX技术博客11 分钟前
【黑金云课堂】VMware Ubuntu 开发环境安装教程
linux·fpga开发·fpga
charlie11451419114 分钟前
嵌入式Linux模块开发——struct module 深度解析:内核模块的核心数据结构
linux·开发语言·数据结构·c
恒创科技HK16 分钟前
恒创科技:刚交付的香港云服务器应该做哪些测试
运维·服务器
刘某的Cloud19 分钟前
svc中外部流量访问限制
linux·运维·docker·kubernetes·service
code monkey.23 分钟前
【寻找Linux的奥秘】Linux 基础 IO 全解析:从 C 库到内核,吃透文件操作的底层逻辑
linux·c语言·基础io