Critical Warnings
Before performing an OpenSSH upgrade in any production environment, you MUST prepare a rollback plan. This includes, but is not limited to: VM snapshots, VM cloning, or documenting executed commands for manual reversion.
Prerequisites
- OpenSSL (May be omitted if the current version is compatible)
- OpenSSH Source Package
Upgrade Procedures
Online upgrades via package managers are generally straightforward. However, for offline compilation, ensure your current SSH session remains active. If the connection is severed during the process, you will be unable to establish a new SSH session until the upgrade is complete, necessitating the use of Telnet or VNC—methods that significantly increase the difficulty of recovery.
1. Online Environment
Upgrading in a connected environment is relatively simple. While you can use package managers like
apt,dnf, oryum, these repositories often lag behind the latest releases. To install the latest version, manual compilation from source is still required.
Ubuntu/Debian
# Update package indexsudo apt update# Check for upgradable OpenSSH versions (Optional)apt list --upgradable openssh-*# Upgrade OpenSSH client and serversudo apt install --only-upgrade openssh-client openssh-server# Restart SSH servicesudo systemctl restart sshd# Verify service status and port listeningsudo systemctl status sshdsudo netstat -tunlp | grep :22RHEL7/CentOS7
# Check for available updatessudo yum check-update# Upgrade OpenSSH componentssudo yum update openssh openssh-server openssh-clients# Restart and verify servicesudo systemctl restart sshdsudo netstat -tunlp | grep :22RHEL8/CentOS8+/RockyLinux9+
# Refresh repository metadatasudo dnf makecache# Upgrade SSH componentssudo dnf upgrade openssh openssh-server openssh-clients# Reload and verify servicesudo systemctl reload sshdsudo netstat -tunlp | grep :222. Isolated Environment (Offline)
Important Recommendations
Recommended versions (as of September 2025):
- OpenSSL: 1.1.1w or 3.x (depending on OS compatibility)
- OpenSSH: 10.0p1 or later
Download links are provided at the end of this article.
Pre-upgrade Preparation
# Create a dedicated workspacemkdir /opt/ssh_upgrade && cd /opt/ssh_upgrade
# Secure backup of existing configurations and binariescp -a /etc/ssh /etc/ssh_backup_$(date +%F)cp -a /etc/init.d/sshd /etc/init.d/sshd_backupcp -a /usr/bin/openssl /usr/bin/openssl_backupcp -a /etc/pam.d/sshd /etc/pam.d/sshd_backup
# Backup critical library dependenciesldd $(which sshd) | awk 'NF == 4 {print $3}' | xargs -I {} cp -a {} /opt/lib_backup/Uninstall Legacy OpenSSH Service
# For Yum-based systemsyum -y remove openssh openssh-server openssh-clients openssh-askpass# Alternative for RPMrpm -e --nodeps openssh openssh-server openssh-clients# For Apt-based systemsapt purge -y openssh-server openssh-clientInstall OpenSSL (Optional)
Omit this step if your current OpenSSL version meets the requirements of the new OpenSSH version.
tar -zxvf openssl-3.2.4.tar.gzcd openssl-3.2.4
# Optimize compilation parameters./config --prefix=/usr/local/openssl \ --openssldir=/usr/local/openssl \ shared zlib -Wl,-rpath=/usr/local/openssl/lib
make && make install
# Update symbolic linksln -sf /usr/local/openssl/bin/openssl /usr/bin/opensslln -sf /usr/local/openssl/include/openssl /usr/include/openssl
# Refresh library cacheecho "/usr/local/openssl/lib" > /etc/ld.so.conf.d/openssl.confldconfig -v | grep -i openssl
# Verify versionopenssl version -aInstall OpenSSH
tar -zxvf openssh-10.6p1.tar.gzcd openssh-10.6p1
# Configure with necessary modules (PAM and Zlib support)./configure --prefix=/usr \ --sysconfdir=/etc/ssh \ --with-ssl-dir=/usr/local/openssl \ --with-pam \ --with-zlib
make -j$(nproc)make install
# Verify binary compatibility and versionldd /usr/sbin/sshdssh -VModify sshd Configuration
vi /etc/ssh/sshd_config
# Ensure the following critical configurations are setPort 22ListenAddress 0.0.0.0PermitRootLogin prohibit-passwordPasswordAuthentication yesUsePAM yesStart the Service
systemctl start sshd# Verify if the service is running correctlysystemctl status sshdđź”— Related Links
[1] Alibaba Cloud OpenSSH Mirror:: https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable
[2] OpenSSL: https://www.openssl.org/source