OpenSSH Security Upgrade Guide: Online and Offline Methods

Translation Notice
This article was originally written in Chinese and translated into English with the assistance of AI. The translation has been reviewed and edited for clarity, accuracy, and readability. Please refer to the original source where necessary, especially for technical terms, commands, configuration details, and proper nouns.
Important Notes
Before upgrading OpenSSH in any production environment, prepare a fallback or rollback plan, such as VM snapshots, VM clones, or a documented command-by-command recovery procedure.
Prerequisites
- OpenSSL (may be omitted if the existing version is compatible)
- OpenSSH
Upgrade Steps
Online upgrades are usually straightforward. For offline compilation and installation, keep your SSH session active throughout the process. If it disconnects, you may not be able to establish another SSH session until the upgrade finishes; you will need Telnet, VNC, or another remote-control protocol, making the upgrade much harder.
Connected Environment
A connected environment is relatively simple: download and upgrade directly with a package manager such as apt, dnf, or yum. Package-manager versions are often not the latest, however, so using the newest release still requires downloading, compiling, and installing it yourself.
Ubuntu/Debian
# Update the package indexsudo apt update# View the available OpenSSH upgrade (optional)apt list --upgradable openssh-*# Upgrade the OpenSSH client and serversudo apt install --only-upgrade openssh-client openssh-server# Restart the SSH servicesudo systemctl restart sshd# Verify the service statussudo systemctl status sshd# Check whether port 22 is listening normallysudo netstat -tunlpRHEL7/CentOS7
# Check for available updatessudo yum check-update# Upgrade OpenSSH alonesudo yum update openssh openssh-server openssh-clients# Restart the servicesudo systemctl restart sshd# Verify the service statussudo systemctl status sshd# Check whether port 22 is listening normallysudo netstat -tunlpRHEL8/CentOS8+/RockyLinux9+
# Refresh repository metadatasudo dnf makecache# Upgrade SSH-related componentssudo dnf upgrade openssh openssh-server openssh-clients# Restart the servicesudo systemctl reload sshd# Verify the service statussudo systemctl status sshd# Check whether port 22 is listening normallysudo netstat -tunlpIsolated Environment (Offline)
Important Notice
Version selection recommendation (September 2025)
- OpenSSL:1.1.1w
- OpenSSH:10.0p1
See the mirror link at the end of this article for the download address.
Preparation
# Create a dedicated working directorymkdir /opt/ssh_upgrade && cd /opt/ssh_upgrade
# Safer backup option (preserve the original files)cp -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
# Back up critical library filesldd $(which sshd) | awk 'NF == 4 {print $3}' | xargs -I {} cp -a {} /opt/lib_backup/Remove the Existing OpenSSH Service
yum -y remove openssh openssh-server openssh-clients openssh-askpass# yum package managerrpm -e --nodeps openssh openssh-server openssh-clients# apt package managerapt purge -y openssh-server openssh-clientInstall OpenSSL (Optional)
You can skip this step if your OpenSSL version is compatible with OpenSSH.
tar -zxvf openssl-3.2.4.tar.gzcd openssl-3.2.4
# Optimize compilation flags./config --prefix=/usr/local/openssl \ --openssldir=/usr/local/openssl \ shared zlib -Wl,-rpath=/usr/local/openssl/lib
make && make install
# Update the security link safelyln -sf /usr/local/openssl/bin/openssl /usr/bin/opensslln -sf /usr/local/openssl/include/openssl /usr/include/openssl
# Verify library dependenciesecho "/usr/local/openssl/lib" > /etc/ld.so.conf.d/openssl.confldconfig -v | grep -i openssl
# Verify the versionopenssl version -aInstall OpenSSH
tar -zxvf openssh-10.6p1.tar.gzcd openssh-10.6p1
# Streamline compilation flags (remove deprecated options)./configure --prefix=/usr \ --sysconfdir=/etc/ssh \ --with-ssl-dir=/usr/local/openssl \ --with-pam \ --with-zlib
make -j$(nproc)make install
# Check binary compatibilityldd /usr/sbin/sshdVerify the Installation
openssl versionssh -VModify the sshd Configuration
vi /etc/ssh/sshd_config
# Write the five configuration lines belowPort 22ListenAddress 0.0.0.0PermitRootLogin prohibit-passwordPasswordAuthentication noUsePAM yesStart the Service
systemctl sshd start🔗 Related links
[1] Aliyun OpenSSH mirror: link
[2] OpenSSL: https://www.openssl.org/source
Support & Share
If this article helped you, please share or support!

Ryan Zhang's Blog


