技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

项目背景与痛点

boypt/openssh-rpms 项目定义了一个脚本,用于将上游的 OpenSSH RPM 包向后移植,以确保系统环境中的 OpenSSH 版本可以及时更新,获得最新的安全补丁和功能特性。OpenSSH 是广泛使用的一款安全加密协议套件实现,用于在不安全的网络中提供服务之间的安全通信。然而,对于一些老旧的系统来说,直接从官方渠道获取的 RPM 包并不能直接兼容系统环境,因此需要这样一个脚本来进行兼容性的调整。

核心技术揭秘

技术架构与原理

boypt/openssh-rpms 主要依赖于 wget 下载上游的 OpenSSH 源代码,然后通过自定义的 Makefile 文件对源代码进行编译与打包操作。关键点在于理解脚本是如何处理不同的系统环境和内核兼容性的。

我们可以看到,该项目主要涉及以下几个步骤:

  1. 下载上游源代码
  2. 根据具体环境对源代码进行 Patch 处理
  3. 编译生成 RPM 包
  4. 安装与测试

图示如下:

graph TD A[下载上游源代码] --> B[应用系统特定 Patch] B --> C[编译源代码] C --> D[打包成 RPM] D --> E[安装并测试]

数据流与处理逻辑

项目以命令行形式运行。从源代码的抓取到具体补丁的处理,再到编译、打包,每一步都有相应的脚本进行管理,确保环境变量与参数被正确设置。这里需要对 OpenSSH 的源代码结构及编译选项有深入了解,而脚本的作用在于自动化和标准化这个流程,以达到零出错的执行效果。

功能亮点与差异

该项目的亮点在于其灵活的补丁处理系统能够针对不同系统环境适配 OpenSSH 的版本,避免直接从官方或第三方渠道下载导致的不兼容问题。尤其对于一些老旧系统而言,本项目并不将它们简单抛弃,反而借助强大的 Patch 引擎提升了更新体验。

另外,项目开源,支持社区成员贡献补丁,共同维护整个项目的可用性和适应性,这是一种开放的、包容的开发者精神体现。

应用场景与落地建议

适合使用本项目的系统类型包括但不限于:

  • 运行老旧的操作系统的服务器
  • 需要长期使用特定版本 OpenSSH 而无法选择官方渠道提供最新版的系统环境
  • 内部安全要求严格,需要定制化 OpenSSH 配置的环境

实践中需要注意的问题主要有:

  • 手动 Patch 部分需要对源代码有深刻的把握,这会增加项目的维护成本
  • 脚本和补丁的更新需要保持与 OpenSSH 项目同步,以免安全性受实际环境变化影响

综合评价

优点

  • 这个项目提供了一种有效的机制,帮助用户在较老的操作系统上仍能获得 OpenSSH 的最新功能和安全更新,保持网络安全。
  • 社区驱动的开发模式,通过不断更新的各种补丁,提升了项目的灵活性和适用性。
  • 提供了自动化构建过程,简化了新环境支持的工作量。

缺点

  • 需要用户有一定的技术实力才能有效应用这些补丁和脚本,对于新手用户可能门槛较高。
  • 手动补丁更新的周期性工作是项目维护的一个痛点,可能会导致更新不能实时跟进最新版本。

简要分析

热度分
908
价值分
378
活跃状态
活跃

语言占比

Shell

Release

README

Backport OpenSSH RPM / SRPM for CentOS

A script to backport upstream OpenSSH for CentOS/RHEL (like) distros.

Similar Project: Backport OpenSSH for Debian / Ubuntu distros

Supported (tested) Distro:

Distro Version Arch Recommended EL RPMs
CentOS 5 x86_64 / i686 EL 5 (rpm-el5-x86_64, rpm-el5-i686)
CentOS 6 x86_64 EL 6 (rpm-el6-x86_64)
CentOS 7 x86_64 / aarch64 EL 7 (rpm-el7-x86_64, rpm-el7-aarch64)
CentOS 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
CentOS Stream 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
CentOS Stream 9 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
Rocky Linux 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
Rocky Linux 9 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
AlmaLinux 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
AlmaLinux 9 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
Oracle Linux 7 x86_64 / aarch64 EL 7 (rpm-el7-x86_64, rpm-el7-aarch64)
Oracle Linux 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
Oracle Linux 9 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
Amazon Linux 1 x86_64 EL 6 (rpm-el6-x86_64)
Amazon Linux 2 x86_64 / aarch64 EL 7 (rpm-el7-x86_64, rpm-el7-aarch64)
Amazon Linux 2023 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
UnionTech UOS V20 x86_64 / aarch64 UOS20 (rpm-uos20-x86_64, rpm-uos20-aarch64)
openEuler 20.03 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
openEuler 22.03 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
openEuler 24.03 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)
AnolisOS 7 x86_64 / aarch64 EL 7 (rpm-el7-x86_64, rpm-el7-aarch64)
AnolisOS 8 x86_64 / aarch64 EL 8 (rpm-el8-x86_64, rpm-el8-aarch64)
AnolisOS 2023 x86_64 / aarch64 EL 9 (rpm-el9-x86_64, rpm-el9-aarch64)

aarch64 RPMs are built from the same el7/ spec via aarch64_el7/8/9 Docker tags (ghcr.io/boypt/openssh-rpms:aarch64_el7 etc., QEMU-built, per-arch tags — not multi-arch manifests).

Project Structure

  • pullsrc.sh: Script to download source packages.
  • compile.sh: Script to build RPMs.
  • version.env: config file for variables (versions, release number, OPENSSL MODE …)

The directory (el5, el6, el7) serve as functional templates for different environment types. The openssh.spec are modified based on the shipped spec file from OpenSSH project.

  • el5: Designed for legacy environments. With toolchains (Perl) to support the build process.
  • el6: With SysVinit startup.
  • el7: With Systemd service.

Note: the Systemd units in el7 are applicable not only to EL7 but also to EL8, EL9, and other modern distributions that rely on Systemd.

Current Version:

The build script reads version.env for version definitions.

OpenSSL is not needed when using WITH_OPENSSL=0. (see version.env)

Build Requirements:

yum install -y autoconf automake gcc make rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel perl perl-IPC-Cmd perl-Time-Piece

# For CentOS7 and above:
yum install -y systemd-devel

# For CentOS5 only:
yum install -y gcc44

libXt-devel, libX11-devel and gtk2-devel are only relevant to the EL6/EL7-era askpass subpackages — the EL8+ spec skips them (compile.sh passes no_gtk2 / skip_gnome_askpass / skip_x11_askpass = 1) and the centos-stream Dockerfile doesn’t install them.

Usage

Download RPMs

Go to the Releases page and download the zip file that matches your system. No script or GitHub API needed.

Each release provides one zip per tag, named like:

openssh_<version>_<tag>.zip

e.g. openssh_v10.5p1_b1_rpm-el8-x86_64.zip.

  1. Find your distro in the “Supported (tested) Distro” table above, and note the tag in the “Recommended EL RPMs” column (e.g. rpm-el8-x86_64).
  2. Download the zip whose name ends with that tag.
  3. Unzip it and install:
unzip openssh*.zip

Build RPMs

Note: It is unnecessary to build on each system, as most RPM-based Linux distributions are glibc compatible. That is, RPMs built on CentOS 8 can be installed and run on Rocky Linux 8/AlmaLinux 8/Oracle Linux 8, etc.

  1. Install build requirements listed above.
  2. Edit version.env file if necessary.
  3. Download source packages.
    ./pullsrc.sh
    
    if any error comes up, manually download the source files into the downloads dir.
  4. Run the script to build RPMs.
    ./compile.sh
    
  5. The generated RPM files will be copied to the output directory.
Use Docker

For more details, see docker/README.md

Install RPMs

ls output
# you will find multiple RPM files in this directory.
# you may copy them to other machines, and continue following steps there.

# Backup current SSH config by moving it away — the new package then
# lays down a fresh stock config, which also avoids breakage from old
# directives (notably the GSSAPI* series) removed upstream.
[[ -f /etc/ssh/sshd_config ]] && mv /etc/ssh/sshd_config /etc/ssh/sshd_config.$(date +%Y%m%d)

# Install rpm packages (`dnf` works the same on EL8/EL9).
sudo yum --disablerepo=* localinstall -y ./openssh*.rpm

# Check Installed version:
ssh -V && /usr/sbin/sshd -V

# If you skipped the backup step above, rpm kept your old config and
# saved the package defaults as sshd_config.rpmnew (the spec marks it
# %config(noreplace)). An old config can keep the new sshd from
# starting, so test it — on failure either fix the offending
# directives, or swap in the .rpmnew defaults, then re-test until it
# passes silently:
ls /etc/ssh/sshd_config.rpmnew
sudo /usr/sbin/sshd -t -f /etc/ssh/sshd_config || sudo mv /etc/ssh/sshd_config{.rpmnew,}
sudo /usr/sbin/sshd -t -f /etc/ssh/sshd_config

# Restart service
sudo systemctl restart sshd   # (`service sshd restart` also works)

# Test a new ssh connection
ssh localhost

DO NOT DISCONNECT current ssh shell yet, open a NEW shell and login to you machine to verify that sshd is working properly.

Troubleshooting

You may get complains during the yum localinstall process. It’s mostly because some subpackages depend on the main openssh package, upgrading only the main package won’t fit in their dependencies.

Commonly these packages are needed to be erased before installing built RPMs.

yum erase openssh-askpass openssh-keycat openssh-cavs openssh-askpass openssh-askpass-gnome openssh-debuginfo

If still not satisfied, you may try the final weapon: FORCED INSTALL.

rpm -ivh --force --nodeps --replacepkgs --replacefiles openssh-*.rpm
Retained sshd_config and /etc/ssh/sshd_config.d/ drop-ins

Legacy /etc/ssh/sshd_config files on many systems do not explicitly include uncommented PasswordAuthentication yes or PermitRootLogin yes lines. Because /etc/ssh/sshd_config is marked %config(noreplace), yum/rpm preserves a user-modified sshd_config during upgrades and writes the package’s template to /etc/ssh/sshd_config.rpmnew.

To prevent root password login from breaking on upgrade while preserving your custom sshd_config, the package’s %post script:

  1. Ensures Include /etc/ssh/sshd_config.d/*.conf is present in /etc/ssh/sshd_config.
  2. Checks whether PermitRootLogin, PasswordAuthentication, and UsePAM are explicitly configured; any missing (or commented-out) directive is written to /etc/ssh/sshd_config.d/99-elssh-defaults.conf.

If you want to customize these settings, either edit /etc/ssh/sshd_config or adjust /etc/ssh/sshd_config.d/99-elssh-defaults.conf, then verify and restart:

sudo /usr/sbin/sshd -t -f /etc/ssh/sshd_config && sudo systemctl restart sshd

Rollback to distro stock OpenSSH

If the custom build doesn’t work for you, remove it and reinstall the version shipped by your distro. Keep your current SSH session open until the rollback is verified.

# 1. Downgrade back to the distro's own versions in one yum transaction.
# (Single yum transaction -> dependencies are handled properly and there
# is no "RPMDB altered outside of yum" warning afterwards. If you
# installed extra subpackages, list them here too.)
sudo yum downgrade openssh openssh-clients openssh-server
# On EL8/EL9, `dnf` works the same.

# Fallback if downgrade is unavailable: erase first, then reinstall
# from the distro repos (re-enable the repos if you disabled them).
sudo rpm -e --nodeps openssh openssh-clients openssh-server
sudo yum install -y openssh openssh-clients openssh-server

# 2. Restart and verify
sudo systemctl restart sshd   # EL7 and above (systemd)
# sudo service sshd restart   # EL5/EL6 (SysVinit)
ssh -V && /usr/sbin/sshd -V
ssh localhost

Notes:

  • The default build bundles OpenSSL statically (WITH_OPENSSL=2), so the system OpenSSL is untouched — only the openssh packages need rolling back.
  • If the downgrade/install step can’t find the packages, your base repos may be disabled or (on EOL releases like EL5/EL6) moved to vault — fix the repo config first.
  • Same rule as install: DO NOT close your current shell, open a NEW shell to verify that login works before disconnecting.

Other Notes

Built without OPENSSL

When built with WITH_OPENSSL=0, ssh-rsa keys are not supported. But the RPMs are much smaller, and the built process is much faster.

Build for uniontech UOS 20

UOS 20 kernels have a do_dup2() bug that triggers a kernel NULL pointer dereference panic when sshd re-execs:

BUG: unable to handle kernel NULL pointer dereference at 000000000000003f
IP: filp_close+0x9/0x70
Call Trace: do_dup2+xxx sys_dup2 entry_SYSCALL_64
PID: xxx Comm: sshd

To apply the workaround (el7/SOURCES/openssh-uos20-kernel-panic-fix.patch, which closes the target fd before each dup2() in sshd.c), set UOS20=1:

UOS20=1 ./compile.sh el8

The flag also prefixes PKGREL with uos20. so the resulting RPMs are distinguishable from the standard build (e.g. PKGREL 1 becomes uos20.1, producing openssh-XXXXX-uos20.1.el7.x86_64.rpm). The patch is only applied when the uos20 macro is set, so ordinary EL7/8/9 builds are unaffected. For the Docker-based build, see docker/README.md.

Install on uniontech UOS 20

UOS’s openssh-help subpackage has files that conflict with the package. It’s must be removed before installing the compiled RPMs:

sudo rpm --nodeps -e openssh-help
sudo yum --disablerepo=* install -y ./openssh*.rpm

评论

暂无评论