Linux,  中标麒麟

how-to-upgrade-OpenSSH-to-10.3p1-on-kylin-v10

 

零 问题现象

某业务系统运行在国产麒麟系统Kylin V10上,业主方委托安全机构非凡进行漏洞扫描。拿到报告之后,大部分和OpenSSH漏洞相关。

序号漏洞名称风险等级加固建议影响资产
1OpenSSH 输入验证错误漏洞(CVE-2020-12062)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/省略服务器IP
2OpenSSH 代码问题漏洞(CVE-2023-38408)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
3OpenSSH 操作系统命令注入漏洞(CVE-2020-15778)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
4OpenSSH 安全漏洞(CVE-2023-51385)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
5OpenSSH 资源管理错误漏洞(CVE-2021-28041)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
6OpenSSH 安全漏洞(CVE-2021-41617)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
7OpenSSH 安全漏洞(CVE-2023-51767)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx
8OpenSSH 远程代码执行漏洞(CVE-2024-6387)高风险若您不需要使用该应用或服务,请关闭该应用或服务即可。 目前厂商已经发布了升级补丁以修复这个安全问题,建议升级到当前最新版本(OpenSSH 10.2或以上)。 Linux系统请在以下页面进行下载: http://www.openssh.com/portable.html 其他版本系统请到厂商主页下载最新版本: http://www.openssh.com/xx

登录到服务器上检查主机和OpenSSH版本相关信息:

[root@ywtg-wjcc-23 ~]# cat /etc/os-release 
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Lance)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Lance)"
ANSI_COLOR="0;31"

[root@ywtg-wjcc-23 ~]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
[root@ywtg-wjcc-23 ~]#

 

一 解决方案:升级SSH到最新版本openssh-10.3p1

根据提示需要对OpenSSH进行升级。

方式一:通过内网/官方仓库进行在线升级;

方式二:对OpenSSH源码编译升级;

 

二 如何通过官方仓库进行升级

由于这台服务器是直接可以访问互联网的,就直接通过麒麟官方的yum源来升级:yum update openssh

[root@ywtg-wjcc-23 ~]# ping www.163.com
PING opencdn126music.jomodns.com (111.132.36.35) 56(84) bytes of data.
64 bytes from 111.132.36.35 (111.132.36.35): icmp_seq=1 ttl=51 time=50.0 ms
64 bytes from 111.132.36.35 (111.132.36.35): icmp_seq=2 ttl=51 time=48.5 ms

^C
--- opencdn126music.jomodns.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 48.549/49.273/49.998/0.724 ms
[root@ywtg-wjcc-23 ~]# rpm -q --changelog openssh | grep CVE-2023-38408
[root@ywtg-wjcc-23 ~]# yum update openssh
Kylin Linux Advanced Server 10 - Os                                                                                                                                                                      4.5 MB/s |  14 MB     00:03    
Kylin Linux Advanced Server 10 - Updates                                                                                                                                                                 7.8 MB/s |  42 MB     00:05    
Last metadata expiration check: 0:00:06 ago on Wed 15 Apr 2026 03:02:47 PM CST.
Dependencies resolved.
=========================================================================================================================================================================================================================================
 Package                                                   Architecture                                     Version                                                     Repository                                                  Size
=========================================================================================================================================================================================================================================
Upgrading:
 openssh                                                   x86_64                                           8.2p1-16.p23.ky10                                           ks10-adv-updates                                           255 k
 openssh-clients                                           x86_64                                           8.2p1-16.p23.ky10                                           ks10-adv-updates                                           538 k
 openssh-server                                            x86_64                                           8.2p1-16.p23.ky10                                           ks10-adv-updates                                           340 k

Transaction Summary
=========================================================================================================================================================================================================================================
Upgrade  3 Packages

Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): openssh-server-8.2p1-16.p23.ky10.x86_64.rpm                                                                                                                                                       554 kB/s | 340 kB     00:00    
(2/3): openssh-8.2p1-16.p23.ky10.x86_64.rpm                                                                                                                                                              410 kB/s | 255 kB     00:00    
(3/3): openssh-clients-8.2p1-16.p23.ky10.x86_64.rpm                                                                                                                                                      457 kB/s | 538 kB     00:01    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                    954 kB/s | 1.1 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                 1/1 
  Running scriptlet: openssh-server-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                         1/1 
  Running scriptlet: openssh-server-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                         1/6 
  Upgrading        : openssh-server-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                         1/6 
warning: /etc/ssh/sshd_config created as /etc/ssh/sshd_config.rpmnew

  Running scriptlet: openssh-server-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                         1/6 
  Running scriptlet: openssh-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                                2/6 
  Upgrading        : openssh-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                                2/6 
  Upgrading        : openssh-clients-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                        3/6 
  Cleanup          : openssh-clients-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                        4/6 
  Cleanup          : openssh-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                                5/6 
  Running scriptlet: openssh-server-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                         6/6 
  Cleanup          : openssh-server-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                         6/6 
  Running scriptlet: openssh-server-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                         6/6 
Warning: The unit file, source configuration file or drop-ins of sshd.service changed on disk. Run 'systemctl daemon-reload' to reload units.

  Verifying        : openssh-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                                1/6 
  Verifying        : openssh-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                                2/6 
  Verifying        : openssh-clients-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                        3/6 
  Verifying        : openssh-clients-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                        4/6 
  Verifying        : openssh-server-8.2p1-16.p23.ky10.x86_64                                                                                                                                                                         5/6 
  Verifying        : openssh-server-8.2p1-16.p07.ky10.x86_64                                                                                                                                                                         6/6 

Upgraded:
  openssh-8.2p1-16.p23.ky10.x86_64                                        openssh-clients-8.2p1-16.p23.ky10.x86_64                                        openssh-server-8.2p1-16.p23.ky10.x86_64                                       

Complete!
[root@ywtg-wjcc-23 ~]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
[root@ywtg-wjcc-23 ~]# rpm -q --changelog openssh | grep CVE-2023-38408
- ID: CVE-2023-38408
- DESC: fix CVE-2023-38408
[root@ywtg-wjcc-23 ~]# rpm -q --changelog openssh | grep -i "CVE-2023-38408"
- ID: CVE-2023-38408
- DESC: fix CVE-2023-38408
[root@ywtg-wjcc-23 ~]# rpm -qa|grep ssh
openssh-help-8.2p1-16.p07.ky10.noarch
openssh-8.2p1-16.p23.ky10.x86_64
libssh-0.9.4-5.ky10.x86_64
openssh-server-8.2p1-16.p23.ky10.x86_64
openssh-clients-8.2p1-16.p23.ky10.x86_64
[root@ywtg-wjcc-23 ~]# 
[root@ywtg-wjcc-23 ~]# rpm -q --changelog openssh | grep -i "CVE-"          
- ID: CVE-2025-61985
- DESC: fix CVE-2025-61985
- ID: CVE-2025-61984
- DESC: fix CVE-2025-61984
- ID: CVE-2025-32728
- DESC: fix CVE-2025-32728
- ID: CVE-2025-26465
- DESC: fix CVE-2025-26465
- ID: CVE-2023-48795
- DESC: fix CVE-2023-48795
- DESC: fix CVE-2023-51385
        add backport-CVE-2023-51385-upstream-ban-user-hostnames-with-most-shell-metachar.patch
- ID: CVE-2023-38408
- DESC: fix CVE-2023-38408
[root@ywtg-wjcc-23 ~]#  

 

升级说明:麒麟操作系统(基于 CentOS/Debian 混合血统)通常会有经过兼容性测试的补丁包。国产系统厂商有时会通过“反向移植(Backporting)”修复漏洞,即版本号看起来没变,但补丁已打入。你可以通过 rpm -q --changelog openssh | grep CVE-2023-38408 确认。可以看到,升级之后,ssh -V看到的版本的确没有变化,但是看到的确有打了补丁了。这就有点儿类似Oracle数据库打PSU/CPU补丁一样。

然后再执行:

[root@ywtg-wjcc-23 ~]# systemctl daemon-reload
[root@ywtg-wjcc-23 ~]# systemctl restart sshd
[root@ywtg-wjcc-23 ~]# systemctl status sshd 
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2026-04-15 15:08:49 CST; 10s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 2924984 (sshd)
    Tasks: 1
   Memory: 936.0K
   CGroup: /system.slice/sshd.service
           └─2924984 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Apr 15 15:08:49 ywtg-wjcc-23 systemd[1]: Starting OpenSSH server daemon...
Apr 15 15:08:49 ywtg-wjcc-23 sshd[2924984]: /etc/ssh/sshd_config line 147: Deprecated option RSAAuthentication
Apr 15 15:08:49 ywtg-wjcc-23 sshd[2924984]: /etc/ssh/sshd_config line 149: Deprecated option RhostsRSAAuthentication
Apr 15 15:08:49 ywtg-wjcc-23 sshd[2924984]: Server listening on 0.0.0.0 port 22.
Apr 15 15:08:49 ywtg-wjcc-23 sshd[2924984]: Server listening on :: port 22.
Apr 15 15:08:49 ywtg-wjcc-23 systemd[1]: Started OpenSSH server daemon.
[root@ywtg-wjcc-23 ~]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
[root@ywtg-wjcc-23 ~]# 

 

这就完成了在线升级。

三 如何通过编译OpenSSH源码进行升级

如果服务器没有配置内网yum源,也没有互联网的yum仓库,我们就得通过手工下载OpenSSH源码,然后进行编译安装升级。

0 首先安装源码编译依赖的工具和环境

yum install -y gcc make zlib-devel openssl-devel pam-devel


[root@ywtg-app-13 openssh-10.3p1]# yum install -y pam-devel                                         
Last metadata expiration check: 0:02:44 ago on Wed 15 Apr 2026 05:20:53 PM CST.
Dependencies resolved.
=========================================================================================================================================================================================================================================
 Package                                             Architecture                                     Version                                                           Repository                                                  Size
=========================================================================================================================================================================================================================================
Installing:
 pam-devel                                           x86_64                                           1.4.0-8.p10.se.06.ky10                                            ks10-adv-updates                                            24 k
Upgrading:
 libchkuid                                           x86_64                                           1.0-3.se.08.ky10                                                  ks10-adv-updates                                            15 k
 pam                                                 x86_64                                           1.4.0-8.p10.se.06.ky10                                            ks10-adv-updates                                           456 k

Transaction Summary
=========================================================================================================================================================================================================================================
Install  1 Package
Upgrade  2 Packages

Total download size: 495 k
Downloading Packages:
(1/3): libchkuid-1.0-3.se.08.ky10.x86_64.rpm                                                                                                                                                             112 kB/s |  15 kB     00:00    
(2/3): pam-1.4.0-8.p10.se.06.ky10.x86_64.rpm                                                                                                                                                             1.7 MB/s | 456 kB     00:00    
(3/3): pam-devel-1.4.0-8.p10.se.06.ky10.x86_64.rpm                                                                                                                                                        74 kB/s |  24 kB     00:00    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                    1.5 MB/s | 495 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                 1/1 
  Running scriptlet: libchkuid-1.0-3.se.08.ky10.x86_64                                                                                                                                                                               1/1 
  Upgrading        : libchkuid-1.0-3.se.08.ky10.x86_64                                                                                                                                                                               1/5 
  Running scriptlet: libchkuid-1.0-3.se.08.ky10.x86_64                                                                                                                                                                               1/5 
  Upgrading        : pam-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                               2/5 
  Running scriptlet: pam-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                               2/5 
  Installing       : pam-devel-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                         3/5 
  Cleanup          : pam-1.4.0-8.p03.se.02.ky10.x86_64                                                                                                                                                                               4/5 
  Running scriptlet: pam-1.4.0-8.p03.se.02.ky10.x86_64                                                                                                                                                                               4/5 
  Cleanup          : libchkuid-1.0-3.se.06.ky10.x86_64                                                                                                                                                                               5/5 
  Running scriptlet: libchkuid-1.0-3.se.06.ky10.x86_64                                                                                                                                                                               5/5 
  Verifying        : pam-devel-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                         1/5 
  Verifying        : libchkuid-1.0-3.se.08.ky10.x86_64                                                                                                                                                                               2/5 
  Verifying        : libchkuid-1.0-3.se.06.ky10.x86_64                                                                                                                                                                               3/5 
  Verifying        : pam-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                               4/5 
  Verifying        : pam-1.4.0-8.p03.se.02.ky10.x86_64                                                                                                                                                                               5/5 

Upgraded:
  libchkuid-1.0-3.se.08.ky10.x86_64                                                                                   pam-1.4.0-8.p10.se.06.ky10.x86_64                                                                                  

Installed:
  pam-devel-1.4.0-8.p10.se.06.ky10.x86_64                                                                                                                                                                                                

Complete!
[root@ywtg-app-13 openssh-10.3p1]# 

 

1 下载openssh-10.3p1源码

访问https://www.openssh.org/portable.html 找到最新版本的https://ftp2.eu.openbsd.org/pub/OpenBSD/OpenSSH/portable/ 10.3p1版本。该版本发布于2026年4月2号,属于非常新的版本。

2 解压编译安装

tar -zxvf openssh-10.3p1.tar.gz 
cd openssh-10.3p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam



[root@ywtg-app-13 ~]# pwd
/root
[root@ywtg-app-13 ~]# ll
total 84096
drwxrwxr-x 2 1000  1000     4096 Mar 25  2025 docker
-rw-r--r-- 1 root root  78805317 Sep 17  2025 docker-28.0.4.tgz
drwxr-xr-x 9  502 games     4096 Feb  2 17:18 nginx-1.28.0
-rw-r--r-- 1 root root   1280111 Feb  2 17:15 nginx-1.28.0.tar.gz
dr-x------ 2 root root      4096 Apr 29  2025 obsutil_linux_amd64_5.7.3
-rw-r--r-- 1 root root   3992450 Apr 29  2025 obsutil_linux_amd64.tar.gz
-rw-r--r-- 1 root root   2007369 Apr 15 15:15 openssh-10.3p1.tar.gz
-rw-r--r-- 1 root root       210 Feb  6 09:39 openssl.cnf
drwxr-xr-x 2 root root      4096 Mar 30 10:42 ssl
[root@ywtg-app-13 ~]# tar -zxvf openssh-10.3p1.tar.gz 
...
openssh-10.3p1/xmalloc.c
openssh-10.3p1/xmalloc.h
[root@ywtg-app-13 ~]# cd openssh-10.3p1
[root@ywtg-app-13 openssh-10.3p1]# ll
total 7752
-rw-r--r-- 1 1000 1000    694 Apr  2 16:09 aclocal.m4
-rw-r--r-- 1 1000 1000  10336 Apr  2 16:09 addr.c
...
[root@ywtg-app-13 openssh-10.3p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam
...

config.status: creating openbsd-compat/regress/Makefile
config.status: creating survey.sh
config.status: creating config.h
configure: WARNING: unrecognized options: --with-md5-passwords

OpenSSH has been configured with the following options:
                     User binaries: /usr/bin
                   System binaries: /usr/sbin
               Configuration files: /etc/ssh
                   Askpass program: /usr/libexec/ssh-askpass
                      Manual pages: /usr/share/man/manX
                          PID file: /var/run
  Privilege separation chroot path: /var/empty
            sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin
                    Manpage format: doc
                       PAM support: yes
                   OSF SIA support: no
                 KerberosV support: no
                   SELinux support: no
                   libedit support: no
                   libldns support: no
  Solaris process contract support: no
           Solaris project support: no
         Solaris privilege support: no
       IP address in $DISPLAY hack: no
           Translate v4 in v6 hack: yes
                  BSD Auth support: no
              Random number source: OpenSSL internal ONLY
             Privsep sandbox style: seccomp_filter
                   PKCS#11 support: yes
                  U2F/FIDO support: yes

              Host: x86_64-pc-linux-gnu
          Compiler: cc
    Compiler flags: -g -O2 -pipe -Wno-error=format-truncation -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -Wimplicit-fallthrough -Wmisleading-indentation -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE  
Preprocessor flags:  -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE
      Linker flags:  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie 
         Libraries: -ldl -lutil  -lresolv
     +for channels: -lcrypto  -lz
         +for sshd: -lcrypt  -lpam

PAM is enabled. You may need to install a PAM control file 
for sshd, otherwise password authentication may fail. 
Example PAM control files can be found in the contrib/ 
subdirectory

[root@ywtg-app-13 openssh-10.3p1]# 

 

configure 成功跑完,这说明你已经解决了所有“编译依赖”问题,系统环境已经准备就绪。

⚠️

  1. 警告提示:-with-md5-passwords 被忽略

日志显示:WARNING: unrecognized options: --with-md5-passwords

  • 原因:在 OpenSSH 10.x 版本中,MD5 密码哈希已经因为安全原因被彻底废弃或默认不再需要该显式参数。
  • 对策:你可以忽略它。现在的 Linux 系统(包括你的麒麟 V10)默认使用更安全的 SHA-512。
  1. 关键点:PAM 配置文件提示
  2. 日志最后那段加粗的提示非常关键: PAM is enabled. You may need to install a PAM control file for sshd
  • 解释:你开启了 PAM 支持(-with-pam),但新安装的 OpenSSH 可能不会自动覆盖你 /etc/pam.d/sshd 的配置。
  • 风险:如果你直接 make install 并重启,可能会导致现有的密码验证失效,让你无法登录。
  • DBA建议:保留你现有的 /etc/pam.d/sshd 文件,它通常是通用的。

3 编译

(使用 nproc 自动获取 CPU 核心数,全力加速编译过程。)

make -j$(nproc)



[root@ywtg-app-13 openssh-10.3p1]# make -j$(nproc)
...
...
cc -o ssh-sk-helper ssh-sk-helper.o ssh-sk.o sk-usbhid.o ssherr-nolibcrypto.o -L. -Lopenbsd-compat/  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie  -lssh -lopenbsd-compat -lssh -lopenbsd-compat -ldl -lutil  -lresolv  -lcrypto  -lz
cc -o sftp sftp.o sftp-usergroup.o progressmeter.o sftp-common.o sftp-client.o sftp-glob.o ssherr-nolibcrypto.o -L. -Lopenbsd-compat/  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie  -lssh -lopenbsd-compat -ldl -lutil  -lresolv 
[root@ywtg-app-13 openssh-10.3p1]# 

 

4 备份旧配置文件

cp /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/bin/ssh /usr/bin/ssh.bak
cp -r /etc/ssh /etc/ssh.bak


[root@ywtg-app-13 openssh-10.3p1]# cp /usr/sbin/sshd /usr/sbin/sshd.bak
[root@ywtg-app-13 openssh-10.3p1]# cp /usr/bin/ssh /usr/bin/ssh.bak
[root@ywtg-app-13 openssh-10.3p1]# cp -r /etc/ssh /etc/ssh.bak
[root@ywtg-app-13 openssh-10.3p1]# 

 

5 安装

make install
[root@ywtg-app-13 openssh-10.3p1]# make install
Makefile:730: warning: ignoring prerequisites on suffix rule definition
(cd openbsd-compat && make)
make[1]: Entering directory '/root/openssh-10.3p1/openbsd-compat'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/root/openssh-10.3p1/openbsd-compat'
/usr/bin/mkdir -p /usr/bin
/usr/bin/mkdir -p /usr/sbin
/usr/bin/mkdir -p /usr/share/man/man1
/usr/bin/mkdir -p /usr/share/man/man5
/usr/bin/mkdir -p /usr/share/man/man8
/usr/bin/mkdir -p /usr/libexec
/usr/bin/mkdir -p -m 0755 /var/empty
/usr/bin/install -c -m 0755 -s ssh /usr/bin/ssh
/usr/bin/install -c -m 0755 -s scp /usr/bin/scp
/usr/bin/install -c -m 0755 -s ssh-add /usr/bin/ssh-add
/usr/bin/install -c -m 0755 -s ssh-agent /usr/bin/ssh-agent
/usr/bin/install -c -m 0755 -s ssh-keygen /usr/bin/ssh-keygen
/usr/bin/install -c -m 0755 -s ssh-keyscan /usr/bin/ssh-keyscan
/usr/bin/install -c -m 0755 -s sshd /usr/sbin/sshd
/usr/bin/install -c -m 0755 -s sshd-session /usr/libexec/sshd-session
/usr/bin/install -c -m 0755 -s sshd-auth /usr/libexec/sshd-auth
/usr/bin/install -c -m 4711 -s ssh-keysign /usr/libexec/ssh-keysign
/usr/bin/install -c -m 0755 -s ssh-pkcs11-helper /usr/libexec/ssh-pkcs11-helper
/usr/bin/install -c -m 0755 -s ssh-sk-helper /usr/libexec/ssh-sk-helper
/usr/bin/install -c -m 0755 -s sftp /usr/bin/sftp
/usr/bin/install -c -m 0755 -s sftp-server /usr/libexec/sftp-server
/usr/bin/install -c -m 644 ssh.1.out /usr/share/man/man1/ssh.1
/usr/bin/install -c -m 644 scp.1.out /usr/share/man/man1/scp.1
/usr/bin/install -c -m 644 ssh-add.1.out /usr/share/man/man1/ssh-add.1
/usr/bin/install -c -m 644 ssh-agent.1.out /usr/share/man/man1/ssh-agent.1
/usr/bin/install -c -m 644 ssh-keygen.1.out /usr/share/man/man1/ssh-keygen.1
/usr/bin/install -c -m 644 ssh-keyscan.1.out /usr/share/man/man1/ssh-keyscan.1
/usr/bin/install -c -m 644 moduli.5.out /usr/share/man/man5/moduli.5
/usr/bin/install -c -m 644 sshd_config.5.out /usr/share/man/man5/sshd_config.5
/usr/bin/install -c -m 644 ssh_config.5.out /usr/share/man/man5/ssh_config.5
/usr/bin/install -c -m 644 sshd.8.out /usr/share/man/man8/sshd.8
/usr/bin/install -c -m 644 sftp.1.out /usr/share/man/man1/sftp.1
/usr/bin/install -c -m 644 sftp-server.8.out /usr/share/man/man8/sftp-server.8
/usr/bin/install -c -m 644 ssh-keysign.8.out /usr/share/man/man8/ssh-keysign.8
/usr/bin/install -c -m 644 ssh-pkcs11-helper.8.out /usr/share/man/man8/ssh-pkcs11-helper.8
/usr/bin/install -c -m 644 ssh-sk-helper.8.out /usr/share/man/man8/ssh-sk-helper.8
/usr/bin/mkdir -p /etc/ssh
/etc/ssh/ssh_config already exists, install will not overwrite
/etc/ssh/sshd_config already exists, install will not overwrite
/etc/ssh/moduli already exists, install will not overwrite
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
/etc/ssh/sshd_config line 80: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 81: Unsupported option GSSAPICleanupCredentials
/etc/ssh/sshd_config line 147: Deprecated option RSAAuthentication
/etc/ssh/sshd_config line 149: Deprecated option RhostsRSAAuthentication
[root@ywtg-app-13 openssh-10.3p1]# 

 

可以看到安装的结果有提示不支持的和已经废弃的算法。

6 检查与修复配置

/usr/sbin/sshd -t

[root@ywtg-app-13 openssh-10.3p1]# /usr/sbin/sshd -t
/etc/ssh/sshd_config line 80: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 81: Unsupported option GSSAPICleanupCredentials
/etc/ssh/sshd_config line 147: Deprecated option RSAAuthentication
/etc/ssh/sshd_config line 149: Deprecated option RhostsRSAAuthentication
[root@ywtg-app-13 openssh-10.3p1]# 

 

检查结果和安装之后执行检查的校验结果一致。我们手工把这些废弃的不支持的算法注释掉,就可以了。

7 修改配置文件,注释废弃或不支持的旧版本的算法

步骤 A:注释掉不支持的 GSSAPI 选项

在 10.3p1 编译时你可能没有开启 Kerberos/GSSAPI 支持,或者新版处理方式变了。

  • 第 80 行GSSAPIAuthentication
  • 第 81 行GSSAPICleanupCredentials操作:在行首添加 # 注释掉。

步骤 B:注释掉弃用的 RSA 验证选项

这些是极老版本的残留,新版已经默认禁用且不再识别这些指令。

  • 第 147 行RSAAuthentication
  • 第 149 行RhostsRSAAuthentication操作:在行首添加 # 注释掉。
# 备份配置文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak2

# 注释掉报错行
sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
sed -i 's/^RSAAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^RhostsRSAAuthentication/#&/' /etc/ssh/sshd_config


[root@ywtg-app-13 openssh-10.3p1]# # 备份配置文件
[root@ywtg-app-13 openssh-10.3p1]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak2
[root@ywtg-app-13 openssh-10.3p1]# 
[root@ywtg-app-13 openssh-10.3p1]# # 注释掉报错行
[root@ywtg-app-13 openssh-10.3p1]# sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
[root@ywtg-app-13 openssh-10.3p1]# sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
[root@ywtg-app-13 openssh-10.3p1]# sed -i 's/^RSAAuthentication/#&/' /etc/ssh/sshd_config
[root@ywtg-app-13 openssh-10.3p1]# sed -i 's/^RhostsRSAAuthentication/#&/' /etc/ssh/sshd_config
[root@ywtg-app-13 openssh-10.3p1]# 

 

8 再次检查确认

[root@ywtg-app-13 openssh-10.3p1]# /usr/sbin/sshd -t
[root@ywtg-app-13 openssh-10.3p1]# 

 

此时,不再有告警。

9 启动新版本OpenSSH服务

# 告知 systemd 配置已变
systemctl daemon-reload

# 重启 SSH 服务
systemctl restart sshd


[root@ywtg-app-13 ~]# # 告知 systemd 配置已变
[root@ywtg-app-13 ~]# systemctl daemon-reload

# 重启 SSH 服务
systemctl restart sshd[root@ywtg-app-13 ~]# 
[root@ywtg-app-13 ~]# # 重启 SSH 服务
[root@ywtg-app-13 ~]# systemctl restart sshd
[root@ywtg-app-13 ~]# 
[root@ywtg-app-13 ~]# systemctl status sshd 
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2026-04-15 17:48:47 CST; 8s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 3028515 (sshd)
    Tasks: 1
   Memory: 572.0K
   CGroup: /system.slice/sshd.service
           └─3028515 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Apr 15 17:48:47 ywtg-app-13 systemd[1]: Starting OpenSSH server daemon...
Apr 15 17:48:47 ywtg-app-13 sshd[3028515]: Server listening on 0.0.0.0 port 22.
Apr 15 17:48:47 ywtg-app-13 sshd[3028515]: Server listening on :: port 22.
Apr 15 17:48:47 ywtg-app-13 systemd[1]: Started OpenSSH server daemon.
[root@ywtg-app-13 ~]# ssh -V
OpenSSH_10.3p1, OpenSSL 1.1.1f  31 Mar 2020
[root@ywtg-app-13 ~]# 

 

至此,OpenSSH通过编译源码的方式,安装升级到最新的10.3p1版本了。保险起见,我们断开和服务器的SSH连接,并重新执行一次SSH连接,验证是否没问题?

四 小结和补充说明

1 OpenSSH是什么?

OpenSSH其全称是Open Secure Shell。说白了,就是原始的通过Telnet方式远程访问服务器不够安全,通过网络传输的数据都是明文。于是,OpenBSD项目下的一帮人站起来了,要管这事儿,他们决定开发一个OpenSSH套件,用于解决远程连接访问服务器的安全协议。我们可以从其官网上看到,

OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.
The OpenSSH suite consists of the following tools:
Remote operations are done using sshscp, and sftp.
Key management with ssh-addssh-keysignssh-keyscan, and ssh-keygen.
The service side consists of sshdsftp-server, and ssh-agent.
OpenSSH is developed by a few developers of the OpenBSD Project and made available under a BSD-style license.
OpenSSH is incorporated into many commercial products, but very few of those companies assist OpenSSH with funding.
Contributions towards OpenSSH can be sent to the OpenBSD Foundation

OpenSSH套件包括我们常用的ssh远程连接,scp加密传输拷贝文件,sftp加密文件传输等。OpenSSH相当于是服务器的一套高级「智能安全门禁系统」。

2 为什么要升级OpenSSH?

从上文我们知道了 OpenSSH 是什么,以及它的作用和功能。既然它对于远程连接、管理、访问、运维服务器非常重要,那么就需要保证这套“门禁系统”的安全和可靠。升级 OpenSSH,其实就相当于升级这套门禁系统的锁芯。长期不升级,可能会出现服务器沦为肉鸡、被恶意利用或被植入木马等风险。

3 升级过程中有哪些注意事项?

务必开启多个 SSH 会话窗口,最好另外单独开启一个 Telnet 窗口,避免升级过程中出现错误或失败,导致与服务器失去远程连接。

升级过程中务必备份升级前与 OpenSSH 相关的配置文件。

软件升级后重启 sshd 服务之前,务必使用新版本 sshd 进行测试和验证,避免重启后服务启动失败。

通过源码编译安装升级之前,确保服务器已安装并配置 gcc、zlib、openssl 和 pam 的开发库。

 

4 pam是什么?pam有什么作用?升级过程中为啥加上 –with-pam 选项?它和OpenSSH啥关系?

Pluggable Authentication Module,顾名思义,可插拔式的认证模块。它的出现具有一定的历史,最早可以追溯到1995年,由Sun公司最早提出,为了解决Solaris操作系统中认证逻辑过于死板、僵化的问题而提出的。因为在早期的Linux系统中,每一个需要登录认证的系统服务,比如ftp服务、Telnet各个模块需要自己写一套独立的用户认证登录系统,并且硬编码了认证登录逻辑。这样的设计有一个缺陷:比如,如果我们想修改操作系统用户密码的加密算法,从DES改为MD5,那么我们就得修改所有需要登录程序(如ftp/Telnet等)的源代码,并且需要重新编译发布。如果下次,再更换或者引入一种新的认证机制的话,这套流程又得再走一遍。如今看来,这就非常非常不方便了。于是,一波儿Sun工程师提出了PAM的雏形,让操作系统的认证模块变得像U盘一样可以实现热插拔,系统管理员只需要修改/etc/pam.d/* 配置文件,就可以实现在不重启、不修改程序的情况下,改变整个系统的安全策略。

PAM除了提供热插拔的认证模块之外,它还提供了可以限制用户使用系统资源的限制机制、可以设定哪些用户只能在什么时间段访问系统、从哪些IP段来访问系统等机制。

展开一点儿,如果你曾经在Unix/Linux系统上安装配置过Oracle数据库的话,那么你一定对于/etc/security/limits.conf文件的配置并不陌生。比如,我手上一台Oracle Linux 9.6的机器上部署了一套单实例的Oracle数据库:

[root@oel-r9u6-11 ~]# cat /etc/oracle-release 
Oracle Linux Server release 9.6
[root@oel-r9u6-11 ~]# head /etc/security/limits.conf 
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means, for example, that setting a limit for wildcard domain here
#can be overridden with a wildcard setting in a config file in the
[root@oel-r9u6-11 ~]# 

 

从该配置文件中,我们可以看到,该文件用于限制那些通过PAM登录服务器的用户对于系统资源使用的限制,此外,/etc/security/limits.d 路径下的所有配置文件,会以字母先后顺序读取生效,那些配置文件里的配置项,也会覆盖掉本文件(/etc/security/limits.conf)里的限制和设置。

顺便给出/etc/security/limits.d/ 路径下的配置文件的配置信息,一看便知:

[root@oel-r9u6-11 ~]# ll /etc/security/limits.d/
total 8
-rw-r--r--. 1 root root  514 Apr 10  2024 25-pw-rlimits.conf
-rw-r--r--. 1 root root 1245 Oct 24 08:53 oracle-ai-database-preinstall-26ai.conf
[root@oel-r9u6-11 ~]# cat /etc/security/limits.d/25-pw-rlimits.conf 
# This file was installed by PipeWire project for its libpipewire-module-rt.so

# It is up to the distribution/user to create the @pipewire group and to add the
# relevant users to the group.
#
# PipeWire will fall back to the RTKit DBus service when the user is not able to
# acquire RT priorities with rlimits.
#
# If the group is not automatically created, the match rule will never be true
# and this file will have no effect.
#
@pipewire   - rtprio  95
@pipewire   - nice    -19
@pipewire   - memlock 4194304
[root@oel-r9u6-11 ~]# cat /etc/security/limits.d/oracle-ai-database-preinstall-26ai.conf 

# oracle-ai-database-preinstall-26ai setting for nofile soft limit is 1024
oracle   soft   nofile    1024

# oracle-ai-database-preinstall-26ai setting for nofile hard limit is 65536
oracle   hard   nofile    65536

# oracle-ai-database-preinstall-26ai setting for nproc soft limit is 16384
# refer orabug15971421 for more info.
oracle   soft   nproc    16384

# oracle-ai-database-preinstall-26ai setting for nproc hard limit is 16384
oracle   hard   nproc    16384

# oracle-ai-database-preinstall-26ai setting for stack soft limit is 10240KB
oracle   soft   stack    10240

# oracle-ai-database-preinstall-26ai setting for stack hard limit is 32768KB
oracle   hard   stack    32768

# oracle-ai-database-preinstall-26ai setting for memlock hard limit is maximum of 128GB on x86_64 or 3GB on x86 OR 90 % of RAM
oracle   hard   memlock    134217728

# oracle-ai-database-preinstall-26ai setting for memlock soft limit is maximum of 128GB on x86_64 or 3GB on x86 OR 90% of RAM
oracle   soft   memlock    134217728

# oracle-ai-database-preinstall-26ai setting for data soft limit is 'unlimited'
oracle   soft   data    unlimited

# oracle-ai-database-preinstall-26ai setting for data hard limit is 'unlimited'
oracle   hard   data    unlimited
[root@oel-r9u6-11 ~]# 

 

话题再转回来,如果我们通过源码编译安装配置 OpenSSH 时不带上 –with-pam 选项,会有什么后果呢?这意味着以后通过 SSH 连接这台服务器时,无法使用 PAM 的热插拔认证模块进行口令校验以及对用户资源使用的限制等认证与控制。

至于说PAM和OpenSSH的关系,好比方用户通过SSH连接到远端的服务器之后,SSH自身不对该用户的用户名、密码进行校验,转而调用PAM进行验证,通过之后,再根据PAM的设置,对用户可以使用的系统资源进行限制。

 

5 补充:OpenSSH和OpenSSL有啥关系?

OpenSSH可以理解为一种远程连接请求的协议和应用层的工具集,而OpenSSL却是底层的一种加解密的密码学库。OpenSSH依赖于OpenSSL,像上述我们在编译安装OpenSSH之前,需要确保系统上已经有安装openssl-devel的库文件原因就在于此。

场景举例说明:用户通过执行 ssh username@server_ip 发起连接请求前,就约定了要使用 AES-256 对通信进行加密。OpenSSH 调用 OpenSSL 的 AES-256 算法对请求进行加密。加密后的数据到达服务端之后,再用同样的算法进行解密。确认加解密一切正常,才算连接成功。大致过程可能类似这样,这是我的理解,实际过程可能更复杂。

OpenSSH场景下使用的命令有:ssh,scp,ssh-keygen等;

OpenSSL场景下使用的常见命令:openssl x509创建或者查看证书等;例如,在某些场景下,需要对NGINX执行自签名的证书,进行HTTPS访问时,就会用到类似下述命令:

openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

 

同时,OpenSSL也常见用于对Web网站的签名证书生成。配置站点的HTTPS证书时,经常会用到.crt和.key的文件,这些就是有OpenSSL生成的证书。

而常见的id_rsa和id_rsa.pub文件,却是由ssh-keygen命令生成的秘钥对文件。不过,ssh-keygen生成秘钥对儿文件时,底层依然是调用了OpenSSL提供的随机数生成器和数学模型来实现的。

升级系统的OpenSSL要比OpenSSH危险系数更高,务必注意。

6 手工编译安装OpenSSH源码的代码清单

yum install -y gcc make zlib-devel openssl-devel pam-devel

tar -zxvf openssh-10.3p1.tar.gz 
cd openssh-10.3p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam


make -j$(nproc)


cp /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/bin/ssh /usr/bin/ssh.bak
cp -r /etc/ssh /etc/ssh.bak

make install


# 备份配置文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak2

# 注释掉报错行
sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
sed -i 's/^RSAAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^RhostsRSAAuthentication/#&/' /etc/ssh/sshd_config


/usr/sbin/sshd -t


# 告知 systemd 配置已变
systemctl daemon-reload

# 重启 SSH 服务
systemctl restart sshd

systemctl status sshd

ssh -V 

 

 

留言