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

相关推荐
有谁看见我的剑了?7 分钟前
介绍一款 测试 DNS解析成功率的网站
运维
半桔11 分钟前
【IO多路转接】高并发服务器实战:Reactor 框架与 Epoll 机制的封装与设计逻辑
linux·运维·服务器·c++·io
HABuo44 分钟前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
Howrun7771 小时前
关于Linux服务器的协作问题
linux·运维·服务器
小白同学_C2 小时前
Lab3-page tables && MIT6.1810操作系统工程【持续更新】
linux·c/c++·操作系统os
十年磨一剑~3 小时前
Linux程序接收到sigpipe信号崩溃处理
linux
geshifei3 小时前
Sched ext回调3——select_cpu(linux 6.15.7)
linux·ebpf
yunfuuwqi3 小时前
OpenClaw✅真·喂饭级教程:2026年OpenClaw(原Moltbot)一键部署+接入飞书最佳实践
运维·服务器·网络·人工智能·飞书·京东云
迎仔3 小时前
C-算力中心网络隔离实施方法:怎么搞?
运维·网络
代码游侠3 小时前
C语言核心概念复习——网络协议与TCP/IP
linux·运维·服务器·网络·算法