CentOS 7.9 OpenSSH 升级实施文档:从 7.4p1 到 10.6p2
7.4p1 → 10.6p2(含 OpenSSL 3.5.9 联编)
| 项目 | 内容 |
|---|---|
| 文档类型 | 系统变更实施文档 |
| 文档版本 | v1.0 |
| 编制日期 | 2026-11-24 |
| 适用系统 | CentOS 7.9 x86_64 |
| 变更范围 | OpenSSH 7.4p1 → 10.6p2;OpenSSL 1.0.2k → 3.5.9 |
| 变更方式 | 源码编译安装(非包管理器) |
| 风险等级 | 中高(涉及远程接入服务替换) |
| 预计耗时 | 40~70 分钟 |
| 回滚方式 | 二进制与配置文件备份恢复 |
| 前置条件 | 具备控制台或第二接入通道;磁盘可用空间 ≥ 3 GB |
1 方案背景与设计
1.1 背景
目标主机运行 CentOS 7.9,OpenSSH 版本为:
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
CentOS 7 已于 2024-06-30 停止维护,官方不再发布安全更新。针对版本类漏洞,可通过配置加固消除弱算法、弱协议等检测项,但无法满足以版本号为准的整改要求。经评估,本次采用源码编译方式将 OpenSSH 升级至当前稳定版本。
1.2 技术约束
经核查 OpenSSH 版本发布说明:自 9.4p1 起,OpenSSH 要求 OpenSSL 版本不低于 1.1.1。
CentOS 7.9 系统提供的 OpenSSL 为 1.0.2k,不满足该约束,因此无法仅升级 OpenSSH。本次实施须同步编译安装 OpenSSL 3.x,形成两级依赖关系:
OpenSSL 3.5.9 → OpenSSH 10.6p2
因此,实施流程必须包含 OpenSSL 编译环节,此为本方案的硬性前提。
1.3 版本选型
| 组件 | 选定版本 | 选型依据 |
|---|---|---|
| OpenSSH | 10.6p2 | 实施时最新稳定版(2026-11-05 发布),包含 10.6 版本的多项安全修复 |
| OpenSSL | 3.5.9 | 官方 LTS 分支,支持期至 2030-04;4.x 系列发布时间较短,不适用于存量系统 |
基础环境:gcc 4.8.5、make 3.82、perl 5.16.3,SELinux 为 Enforcing,FIPS 未启用。
gcc 4.8.5 可满足 OpenSSL 3.5 与 OpenSSH 10.6 的编译要求,无需引入 devtoolset。
1.4 总体流程与风险分布
| 阶段 | 内容 | 是否影响在线服务 | 检查点 |
|---|---|---|---|
| 一 | 环境准备 | 否 | 源码包完整、依赖齐全 |
| 二 | 编译 OpenSSL | 否 | openssl version 为 3.5.9 |
| 三 | 编译 OpenSSH | 否 | 版本、动态库、辅助二进制均正确 |
| 四 | 配置适配 | 否 | 新旧二进制语法检查均通过 |
| 五 | 服务切换 | 是 | 新会话可正常登录 |
| 六 | 登录验证 | 否 | 认证策略符合预期 |
前四个阶段不修改任何运行中的组件,新版本仅存在于暂存目录;风险集中于阶段五的一次服务重启。
阶段一 环境准备
│ 检查点①
阶段二 编译 OpenSSL 3.5.9 → /usr/local/openssl3
│ 检查点②
阶段三 编译 OpenSSH 10.6p2 → /tmp/ssh-new(不动系统)
│ 检查点③
阶段四 配置适配(不切换)
│ 检查点④
阶段五 替换二进制 + 重启服务(唯一风险点)
│ 检查点⑤
阶段六 登录验证与策略调整
2 实施流程
2.1 阶段一:环境准备
步骤 1-1 系统信息采集
采集以下信息作为变更基线,便于故障时比对。
cat /etc/redhat-release
ssh -V
getenforce
cat /proc/sys/crypto/fips_enabled 2>/dev/null || echo "未启用 FIPS"
df -h /usr/local /tmp
验证标准:
ssh -V输出为 7.4p1;/usr/local或/tmp可用空间不少于 3 GB;- 记录
getenforce当前状态。
若
fips_enabled返回1,须先行确认合规要求。升级后 SSH 使用自行编译的 OpenSSL,不属于 FIPS 验证模块。
步骤 1-2 依赖安装
yum -y install gcc make perl zlib-devel pam-devel libselinux-devel \
wget curl gnupg2
rpm -q gcc make perl zlib-devel pam-devel libselinux-devel
验证标准:六项均返回已安装版本,无 is not installed 提示。

图 1 编译依赖检查结果
步骤 1-3 源码获取与校验
mkdir -p /root && cd /root
wget -q https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz
wget -q https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz.sha256
sha256sum -c openssl-3.5.9.tar.gz.sha256
B=https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable
wget -q $B/openssh-10.6p2.tar.gz
wget -q $B/openssh-10.6p2.tar.gz.asc
wget -q https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/RELEASE_KEY.asc
gpg --import RELEASE_KEY.asc
gpg --verify openssh-10.6p2.tar.gz.asc openssh-10.6p2.tar.gz
tar tzf openssh-10.6p2.tar.gz | head -3
tar tzf openssl-3.5.9.tar.gz | head -3
验证标准:解压目录为 openssh-10.6p2/ 与 openssl-3.5.9/。文件大小分别约为 2.2 MB 与 51 MB,若明显偏小,说明下载内容异常。

图 2 升级包完整性验证
说明一:
RELEASE_KEY.asc在浏览器中访问时以纯文本形式内联显示,不触发下载。该文件本身为 ASCII 格式公钥,使用wget或curl获取结果正常。说明二:
gpg --verify输出中的This key is not certified with a trusted signature!为本地缺少信任链所致,只要存在Good signature即表示校验通过。
2.2 阶段二:编译 OpenSSL 3.5.9
本阶段不修改系统现有组件,安装目标为独立目录
/usr/local/openssl3。
步骤 2-1 配置
cd /root
tar xzf openssl-3.5.9.tar.gz
cd openssl-3.5.9
./config --prefix=/usr/local/openssl3 --openssldir=/usr/local/openssl3 shared zlib
配置脚本名称为
config,非configure。
异常处理:Perl 模块缺失
配置阶段中断,报错如下:
Can't locate IPC/Cmd.pm in @INC (you may need to install the IPC::Cmd module)
BEGIN failed--compilation aborted at /root/openssl-3.5.9/util/perl/OpenSSL/config.pm line 19.
Compilation failed in require at /root/openssl-3.5.9/Configure line 23.

图 3 Perl 模块缺失报错
原因:CentOS 7 将 Perl 核心模块拆分为独立 RPM 包,IPC::Cmd 不在默认安装集合内,而 OpenSSL 3.x 配置脚本依赖该模块。
处置:
yum -y install perl-IPC-Cmd perl-core
安装完成后重新执行 ./config,无需 make clean(配置阶段中断不会生成构建文件)。
同类问题的处理规则:出现
Can't locate A/B.pm时,执行yum -y install perl-A-B(路径分隔符替换为连字符)。安装perl-core可一次性补齐其余核心模块。
修复后重新执行配置,验证标准为输出包含 OpenSSL has been successfully configured:

图 4 OpenSSL 配置成功
步骤 2-2 编译
make -j$(nproc)
验证标准:编译过程无 Error 输出。耗时通常 8~15 分钟,过程中出现大量 making all in crypto... 属正常输出。
异常处理:并行编译偶发竞态错误时,可先以 make -j2 重试,无需立即执行 make clean。
步骤 2-3 安装与动态库注册
make install_sw
ls -d /usr/local/openssl3/lib*
SSL_LIB=$(ls -d /usr/local/openssl3/lib64 2>/dev/null || echo /usr/local/openssl3/lib)
echo $SSL_LIB > /etc/ld.so.conf.d/openssl3.conf
ldconfig
/usr/local/openssl3/bin/openssl version
验证标准:输出为 OpenSSL 3.5.9 ...。

图 5 OpenSSL 版本与头文件验证
注意:部分参考资料包含以下操作,不得执行:
ln -sf /usr/local/openssl3/bin/openssl /usr/bin/openssl该操作会覆盖系统自带的 openssl 命令行工具,可能影响 yum、证书处理脚本及其他依赖组件,且回滚困难。本次仅通过
--with-ssl-dir使 sshd 链接新版本库,系统 openssl 保持不变。
2.3 阶段三:编译 OpenSSH 10.6p2
本阶段不修改系统任何现有文件:不覆盖
/usr/sbin/sshd,不修改/etc/ssh,新版本仅安装至暂存目录。
步骤 3-1 配置
cd /root
tar xzf openssh-10.6p2.tar.gz
cd openssh-10.6p2
SSL_LIB=/usr/local/openssl3/lib64
LDFLAGS="-Wl,-rpath,$SSL_LIB" ./configure \
--prefix=/usr \
--sysconfdir=/etc/ssh \
--libexecdir=/usr/libexec/openssh \
--with-privsep-path=/var/empty/sshd \
--with-pam --with-zlib --with-md5-passwords --with-selinux \
--with-ssl-dir=/usr/local/openssl3
各参数作用及缺失影响:
| 参数 | 作用 | 缺失后果 |
|---|---|---|
--sysconfdir=/etc/ssh |
读取现有配置目录 | 生成独立配置,与现有配置冲突 |
--libexecdir=/usr/libexec/openssh |
使 sftp-server 安装至现有路径 |
与 Subsystem sftp 配置不符,SFTP 不可用 |
--with-privsep-path=/var/empty/sshd |
使用系统既有目录 | 目录不存在,服务启动失败 |
LDFLAGS=-rpath,... |
二进制内嵌库搜索路径 | 依赖全局 ldconfig,影响其他程序 |
--with-ssl-dir |
指定新版本 OpenSSL | 链接至旧版本库,本阶段工作无效 |
验证标准:配置摘要中应包含以下内容:
Configuration files: /etc/ssh
Privilege separation chroot: /var/empty/sshd
PAM support: yes
SELinux support: yes
Kerberos support: no
Linker flags: ... -Wl,-rpath,/usr/local/openssl3/lib64 ...

图 6 OpenSSH configure 输出摘要
需注意两点:
WARNING: unrecognized options: --with-md5-passwords属正常提示,该选项在 10.x 中已移除,不影响编译结果。Kerberos support: no表示未编译 GSSAPI 支持,阶段四须注释sshd_config中的 GSSAPI 相关指令,否则新版本服务无法启动。
步骤 3-2 编译
make -j$(nproc)
验证标准:编译过程无 Error 输出,耗时通常 2~5 分钟。
步骤 3-3 安装至暂存目录
rm -rf /tmp/ssh-new
make install DESTDIR=/tmp/ssh-new
DESTDIR参数不可省略。不带该参数执行make install将直接覆盖/usr/sbin/sshd,并覆盖/etc/ssh/sshd_config,导致端口、AllowUsers、密钥等现有配置丢失。
异常处理:主机私钥权限不足
安装末尾的配置自检阶段中断,报错如下:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
sshd: no hostkeys available -- exiting.
make: [check-config] Error 1 (ignored)

图 7 主机私钥权限异常与修正
该输出包含两个独立问题,须区分处理:
其一,Error 1 (ignored) 不代表安装失败。 OpenSSH 的 Makefile 中 check-config 目标带有 - 前缀,失败不会中断安装流程。安装文件实际已完整写入暂存目录,无需重装。
其二,实际问题为主机私钥权限过宽。 权限 0640 使同组用户具备读权限,新版本 sshd 将丢弃此类密钥,导致无可用主机密钥,服务无法启动。
处置:
ls -l /etc/ssh/ssh_host_*_key
chmod 600 /etc/ssh/ssh_host_*_key
ls -l /etc/ssh/ssh_host_*_key
仅修改私钥文件,公钥保持 644。修正后执行自检确认:
/tmp/ssh-new/usr/sbin/sshd -t -f /tmp/ssh-new/etc/ssh/sshd_config && echo "SELF-CHECK OK"
该问题若在服务重启后才暴露,将直接导致 SSH 服务不可用。采用“先安装至暂存目录、再执行自检”的方式,可在切换前发现并处理,属于本方案的关键设计。
步骤 3-4 预检
/tmp/ssh-new/usr/sbin/sshd -V
ldd /tmp/ssh-new/usr/sbin/sshd | grep -E 'libcrypto|libssl'
ls -l /tmp/ssh-new/usr/libexec/openssh/
三项须同时满足:
| 序号 | 检查项 | 期望结果 |
|---|---|---|
| 1 | 版本 | OpenSSH_10.6p2, OpenSSL 3.5.9 ... |
| 2 | 动态库 | libcrypto.so.3 => /usr/local/openssl3/lib64/libcrypto.so.3 |
| 3 | 辅助二进制 | sshd-auth、sshd-session 等文件存在 |

图 8 新二进制预检结果
第 3 项为 10.0 起的新增要求。OpenSSH 自 10.0 版本将认证逻辑从主进程拆分为
sshd-auth与sshd-session两个独立二进制。缺失这两个文件时,服务可正常监听端口、banner 显示正常,但所有认证请求均会失败,且日志中不一定产生明确错误信息。
2.4 阶段四:配置适配
本阶段仍不执行切换,目标是在新版本可接受的前提下,保证旧版本配置仍合法。
步骤 4-1 配置备份
CFG=/etc/ssh/sshd_config
cp -a $CFG /root/sshd_config.$(date +%H%M%S).bak
步骤 4-2 废弃指令清理
CFG=/etc/ssh/sshd_config
# 7.x 已移除的指令;本次未编译 Kerberos 支持,GSSAPI 相关指令须一并注释
sed -i -E 's/^[[:space:]]*(Protocol|UsePrivilegeSeparation|RhostsRSAAuthentication|RSAAuthentication|KeyRegenerationInterval|ServerKeyBits|UseLogin|GSSAPIAuthentication|GSSAPICleanupCredentials|GSSAPIKexAlgorithms|GSSAPIStrictAcceptorCheck|KerberosAuthentication)([[:space:]]|$)/# &/' $CFG
# 指令更名
sed -i -E 's/^[[:space:]]*ChallengeResponseAuthentication[[:space:]]+([a-zA-Z]+)/KbdInteractiveAuthentication \1/' $CFG
# RHEL 私有补丁参数,上游版本不支持
sed -i -E 's/^[[:space:]]*CRYPTO_POLICY=/# &/' /etc/sysconfig/sshd 2>/dev/null
grep -nE 'GSSAPI|KbdInteractive' $CFG
验证标准:GSSAPI 相关行均已注释。
步骤 4-3 新旧版本双重语法检查
/usr/sbin/sshd -t && echo "旧二进制:配置 OK"
/tmp/ssh-new/usr/sbin/sshd -t -f /etc/ssh/sshd_config && echo "新二进制:配置 OK"
验证标准:两行 OK 均需出现。
对旧版本执行检查的目的,是确认修改后的配置对当前运行版本同样合法,避免出现新旧版本均无法解析的中间状态。
异常处理:新版本报 Bad configuration option: xxx 时,注释对应行后重新执行两条检查命令。
步骤 4-4 systemd 单元类型修正
grep -E '^Type=' /usr/lib/systemd/system/sshd.service
若输出为 Type=notify,须执行修正。原因:RHEL 为 sshd 增加了 sd_notify 补丁,单元类型为 notify;本次编译的上游版本不发送该通知,systemd 将等待至超时并判定启动失败,而实际进程已正常运行。
处置(采用 drop-in 覆盖,不修改系统单元文件):
if grep -qE '^Type=notify' /usr/lib/systemd/system/sshd.service; then
mkdir -p /etc/systemd/system/sshd.service.d
printf '[Service]\nType=simple\n' > /etc/systemd/system/sshd.service.d/10-upstream.conf
echo "已改为 Type=simple"
else
echo "无需修改 systemd 单元"
fi

图 9 配置适配与 systemd 单元修正
2.5 阶段五:服务切换
本阶段为全流程唯一风险点。执行前须确认当前终端保持连接。
CentOS 7 的 sshd.service 配置为
KillMode=process,systemctl restart仅重启主进程,既有会话不会中断。因此即使新版本启动失败,仍可通过当前会话执行回滚。
步骤 5-1 回滚素材确认
source /root/ssh-backup.env
echo "备份目录:$BK"
ls -l $BK/sshd.bin && echo "回滚素材就位"
备份目录应包含 sshd.bin、libexec-old/、etc-ssh/ 三项。
步骤 5-2 主二进制替换
install -m 755 /tmp/ssh-new/usr/sbin/sshd /usr/sbin/sshd
for b in ssh scp sftp ssh-add ssh-agent ssh-keygen ssh-keyscan; do
install -m 755 /tmp/ssh-new/usr/bin/$b /usr/bin/$b
done
install不会触发覆盖确认,适用于本场景。
替换完成后,ssh -V 与 /usr/sbin/sshd -V 均显示 10.6p2。需注意此时显示的仍是命令行客户端版本,服务端进程尚未重启,实际版本以 banner 为准。

图 10 二进制替换后的版本显示
步骤 5-3 辅助二进制替换
/bin/cp -a /tmp/ssh-new/usr/libexec/openssh/. /usr/libexec/openssh/
必须使用
/bin/cp,不得使用cp。CentOS 7 的 root 默认配置alias cp='cp -i',覆盖确认的默认回答为“否”,将导致文件未被替换。
验证标准如下,五项须全部返回 OK:
for f in sftp-server ssh-keysign ssh-pkcs11-helper sshd-auth sshd-session; do
printf '%-20s ' "$f"
cmp -s /usr/libexec/openssh/$f /tmp/ssh-new/usr/libexec/openssh/$f && echo OK || echo DIFF
done

图 11 辅助二进制一致性校验
异常处理之一:文件未被替换
若使用 cp 执行,会出现覆盖确认:
cp: overwrite '/usr/libexec/openssh/./ssh-keysign'?
cp: overwrite '/usr/libexec/openssh/./ssh-pkcs11-helper'?
cp: overwrite '/usr/libexec/openssh/./sftp-server'?
直接回车即选择“不覆盖”。该问题具有较强隐蔽性:sshd-auth、sshd-session 为新文件,不触发确认并正常写入;而 sftp-server、ssh-keysign、ssh-pkcs11-helper 三个既有文件全部未更新。此时 /usr/sbin/sshd 已被 install 替换,ssh -V 显示正常,常规检查难以发现该状态。
须通过校验和比对确认:
md5sum /usr/libexec/openssh/sftp-server /tmp/ssh-new/usr/libexec/openssh/sftp-server

图 12 校验和不一致,确认文件未替换
处置:改用 /bin/cp 重新执行,并以上述 cmp 循环逐项复核。
异常处理之二:Text file busy
改用 /bin/cp 后仍可能失败:
/bin/cp: cannot create regular file '/usr/libexec/openssh/./sftp-server': Text file busy

图 13 Text file busy 报错
ETXTBSY 表示目标文件正在被进程执行。确认占用情况:
ps -ef | grep '[s]ftp'

图 14 占用 sftp-server 的进程
上例中存在四个残留 SFTP 会话,持续时间接近一小时,分别挂载于两个会话进程之下。
处置方式为“同目录写入临时文件 + mv -f 重命名”。rename(2) 仅替换目录项,不修改原 inode,因此不受文件占用影响:
cd /usr/libexec/openssh
/bin/cp -a /tmp/ssh-new/usr/libexec/openssh/sftp-server .sftp-server.new
mv -f .sftp-server.new sftp-server
原进程继续持有旧 inode 直至退出,新连接使用新文件。该方式与系统包管理器的升级机制一致,无需终止他人会话。
步骤 5-4 权限与 SELinux 标签
chmod 4755 /usr/libexec/openssh/ssh-keysign
restorecon -Rv /usr/sbin/sshd /usr/bin/ssh /usr/libexec/openssh >/dev/null 2>&1 || true
ls -l /usr/libexec/openssh/
验证标准:ssh-keysign 权限为 -rwsr-xr-x,包含 setuid 位。
步骤 5-5 服务重启
systemctl daemon-reload
systemctl restart sshd
验证:
systemctl status sshd --no-pager -l | head -15
ss -tlnp | grep ':22'
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-v 127.0.0.1 true 2>&1 | grep -i 'remote software version'
期望结果:
Active: active (running) ...
LISTEN 0 128 *:22 ... users:(("sshd",pid=...,fd=6))
debug1: Remote protocol version 2.0, remote software version OpenSSH_10.6

图 15 重启后服务状态与版本验证
随后须新开终端执行一次登录,确认认证链路可用。该操作为本次变更成功与否的唯一判定依据。
2.6 阶段六:登录验证与策略调整
步骤 6-1 登录验证
使用新终端连接目标主机。若登录失败,应先区分服务异常与认证策略限制,不宜直接判定升级失败。
异常处理:密码认证被拒绝
客户端提示密码被拒:

图 16 客户端提示“服务器拒绝了密码”
此时对话框显示 服务器类型: SSH2, OpenSSH_10.6,说明连接已建立、banner 正常、新版本服务已生效,问题位于认证环节而非服务本身。
执行配置与日志检查:
sshd -T | grep -iE '^(permitrootlogin|passwordauthentication|usepam)'
journalctl -u sshd --since "10 min ago" --no-pager | grep -iE 'error|fail|denied|avc'

图 17 认证相关配置与运行状态检查
该例输出 permitrootlogin prohibit-password,含义为 root 用户仅允许密钥认证。本次变更未修改该配置项,该策略在升级前即已存在,客户端本次默认选择了密码认证方式。
其余检查项均正常:passwd -S root 显示密码有效(SHA512 crypt)、/etc/pam.d/sshd 存在、sshd-auth 无缺失依赖、SELinux 处于 Enforcing 但无拒绝记录。
判定依据:
| 现象 | 结论 |
|---|---|
permitrootlogin prohibit-password |
认证策略限制,按步骤 6-2 处理 |
日志含 PAM: Authentication failure |
PAM 认证链路异常,检查 /etc/pam.d/sshd |
| 日志无新增记录 | 请求未到达本机,核对目标地址与端口 |
步骤 6-2 认证策略调整
确需启用 root 密码登录时:
CFG=/etc/ssh/sshd_config
cp -a $CFG /root/sshd_config.bak.$(date +%H%M%S)
if grep -qE '^[[:space:]]*#?[[:space:]]*PermitRootLogin' $CFG; then
sed -i -E 's/^[[:space:]]*#?[[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' $CFG
else
echo 'PermitRootLogin yes' >> $CFG
fi
sshd -T | grep -i permitrootlogin
sshd -t && systemctl reload sshd
reload 即可生效,无需重启服务,不影响现有连接。
若主机具备公网地址,启用 root 密码登录将显著增加暴力破解风险。建议优先为 root 配置密钥认证,或通过来源地址限制收敛访问范围。
步骤 6-3 功能验证
ssh -V
sshd -T | grep -Ei '^(ciphers|macs|kexalgorithms)'
sftp localhost
版本号显示存在差异:
ssh -V输出OpenSSH_10.6p2,而 banner 显示SSH-2.0-OpenSSH_10.6。自 10.0 版本起,发行版标识不再附加 p 后缀,属正常现象。
3 回滚与后续操作
3.1 回滚操作
source /root/ssh-backup.env
/bin/cp -a $BK/sshd.bin /usr/sbin/sshd
/bin/cp -a $BK/libexec-old/. /usr/libexec/openssh/
/bin/cp -a $BK/etc-ssh/sshd_config /etc/ssh/sshd_config
rm -f /etc/systemd/system/sshd.service.d/10-upstream.conf
systemctl daemon-reload && systemctl restart sshd
回滚机制的保障点:
| 措施 | 作用 |
|---|---|
新版本先安装至 /tmp/ssh-new |
校验通过前不修改系统组件,任意时刻可中止 |
| 旧二进制完整备份 | 回滚不依赖重新编译 |
KillMode=process |
重启不中断既有会话,新版本异常时仍具备操作通道 |
备份路径写入 /root/ssh-backup.env |
无需人工记录时间戳 |
3.2 防止包管理器覆盖
cp -a /etc/yum.conf /root/yum.conf.bak
if grep -q '^exclude=' /etc/yum.conf; then
sed -i 's/^exclude=\(.*\)/exclude=\1,openssh*/' /etc/yum.conf
else
echo 'exclude=openssh*' >> /etc/yum.conf
fi
未配置该项时,后续任何 yum update 操作均可能将 /usr/sbin/sshd 覆盖回 7.4 版本,导致漏洞状态复原。
3.3 客户端兼容性
| 现象 | 原因 |
|---|---|
no matching key exchange method |
10.0 起 sshd 默认禁用有限域 DH 密钥交换 |
no mutual signature algorithm |
8.8 起默认禁用 ssh-rsa(SHA-1)签名 |
scp 传输异常 |
9.0 起 scp 默认使用 SFTP 协议,需附加 -O 参数 |
确需兼容旧版本客户端时,可追加以下配置:
cat >> /etc/ssh/sshd_config <<'EOF'
KexAlgorithms +diffie-hellman-group14-sha1
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
EOF
sshd -t && systemctl reload sshd
上述配置将重新启用弱算法,可能导致漏洞扫描再次判定为风险项。建议先确认存在实际连接失败的客户端后再启用。
3.4 重启验证
reboot
重启后重新确认:
ssh -V
systemctl status sshd --no-pager | head -5
并再次执行登录验证。编译安装方式的问题常在重启后暴露,该步骤不可省略。
4 结论与建议
4.1 版本跨度评估
本次由 7.4p1 升级至 10.6p2,跨越 6 年、5 个大版本,累积的不兼容变更包括:DSA 算法移除、有限域 DH 默认禁用、ssh-rsa 签名禁用、scp 传输协议变更、认证进程拆分等,均可能影响现有业务。
若整改要求不限定具体版本,建议评估 9.3p2 方案:9.4p1 为 OpenSSL 1.1.1 要求的分界版本,9.3p2 是最后一个可使用系统 OpenSSL 1.0.2k 编译的版本,实施成本显著降低。
4.2 验证环节的关键作用
本次实施中影响最大的异常均非编译错误,而是状态误判:
| 误判现象 | 实际情况 |
|---|---|
Error 1 (ignored) |
安装已成功完成 |
cp 出现覆盖提示 |
文件实际未被替换 |
服务状态 active (running) |
认证子系统可能不可用 |
ssh -V 显示新版本 |
这是客户端版本,非服务端版本 |
因此,流程中的以下校验动作具有关键作用,不可省略:
- 使用
DESTDIR安装至暂存目录; - 使用新旧两个二进制分别执行
sshd -t; - 使用
cmp逐项比对辅助二进制; - 服务重启后通过新开终端验证登录。
附录 A 异常速查表
现场处置时可据此快速定位,详细分析见“实施流程”中对应步骤。
| 编号 | 现象 / 报错信息 | 根本原因 | 处置方法 | 对应位置 |
|---|---|---|---|---|
| 1 | Can't locate IPC/Cmd.pm in @INC |
Perl 核心模块拆分为独立子包 | yum -y install perl-IPC-Cmd perl-core |
步骤 2-1 |
| 2 | UNPROTECTED PRIVATE KEY FILE / no hostkeys available |
主机私钥权限为 0640 | chmod 600 /etc/ssh/ssh_host_*_key |
步骤 3-3 |
| 3 | make: [check-config] Error 1 (ignored) |
目标带 - 前缀,失败不中断 |
非错误,安装已完成 | 步骤 3-3 |
| 4 | unrecognized options: --with-md5-passwords |
该选项在 10.x 已移除 | 忽略 | 步骤 3-1 |
| 5 | 服务已运行但 systemd 判定失败 | Type=notify 与上游版本不匹配 |
drop-in 覆盖为 Type=simple |
步骤 4-4 |
| 6 | cp -i 提示覆盖,确认后文件未更新 |
root 默认 alias cp='cp -i' |
改用 /bin/cp 或 install |
步骤 5-3 |
| 7 | cannot create regular file ...: Text file busy |
目标文件正被执行中 | 临时文件 + mv -f 替换 |
步骤 5-3 |
| 8 | 客户端提示“服务器拒绝了密码” | PermitRootLogin prohibit-password |
调整策略或改用密钥认证 | 步骤 6-1 |
| 9 | banner 显示 OpenSSH_10.6 而非 10.6p2 |
10.x 版本标识规则 | 正常现象 | 步骤 6-3 |
关于本文的记录方式:文中所列操作均在真实 CentOS 7.9 主机上逐步执行,命令、回显与截图取自实际操作过程。AI 助手参与了过程记录、文档整理与排版校对,所有命令及执行结果均经人工复核。

浙公网安备 33010602011771号