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

相关推荐
GuokLiu3 小时前
250708-Debian系统安装Edge浏览器并配置最小中文输入法
运维·edge·debian
Two_brushes.3 小时前
【linux 网络】网络基础
linux·网络
Code Warrior3 小时前
【Linux】基础开发工具(3)
linux·服务器
鬼才血脉4 小时前
Linux(centos)安装 MySQL 8
linux·mysql·centos
guygg884 小时前
ubuntu手动编译VTK9.3 Generating qmltypes file 失败
linux·运维·ubuntu
JeffersonZU5 小时前
Linux/Unix 套接字Socket编程(socket基本概念,流程,流式/数据报socket,Unix domain socket示例)
linux·c语言·tcp/ip·udp·unix·gnu
先做个垃圾出来………5 小时前
自动化一次通过率
运维·自动化
Two_brushes.5 小时前
【linux网络】网络编程全流程详解:从套接字基础到 UDP/TCP 通信实战
linux·开发语言·网络·tcp/udp
夕泠爱吃糖6 小时前
Linux中的静态库和动态库
linux·运维·服务器
比奥利奥还傲.7 小时前
Linux运维安全新范式:基于TCPIP与SSH密钥的无密码认证实战
linux·运维·安全