Video failed to load

OpenSSH Security Upgrade Guide: Online and Offline Methods

567 words
3 minutes
OpenSSH Security Upgrade Guide: Online and Offline Methods
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#

  1. OpenSSL (may be omitted if the existing version is compatible)
  2. 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#

Terminal window
# Update the package index
sudo apt update
# View the available OpenSSH upgrade (optional)
apt list --upgradable openssh-*
# Upgrade the OpenSSH client and server
sudo apt install --only-upgrade openssh-client openssh-server
# Restart the SSH service
sudo systemctl restart sshd
# Verify the service status
sudo systemctl status sshd
# Check whether port 22 is listening normally
sudo netstat -tunlp

RHEL7/CentOS7#

Terminal window
# Check for available updates
sudo yum check-update
# Upgrade OpenSSH alone
sudo yum update openssh openssh-server openssh-clients
# Restart the service
sudo systemctl restart sshd
# Verify the service status
sudo systemctl status sshd
# Check whether port 22 is listening normally
sudo netstat -tunlp

RHEL8/CentOS8+/RockyLinux9+#

Terminal window
# Refresh repository metadata
sudo dnf makecache
# Upgrade SSH-related components
sudo dnf upgrade openssh openssh-server openssh-clients
# Restart the service
sudo systemctl reload sshd
# Verify the service status
sudo systemctl status sshd
# Check whether port 22 is listening normally
sudo netstat -tunlp

Isolated 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#

Terminal window
# Create a dedicated working directory
mkdir /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_backup
cp -a /usr/bin/openssl /usr/bin/openssl_backup
cp -a /etc/pam.d/sshd /etc/pam.d/sshd_backup
# Back up critical library files
ldd $(which sshd) | awk 'NF == 4 {print $3}' | xargs -I {} cp -a {} /opt/lib_backup/

Remove the Existing OpenSSH Service#

Terminal window
yum -y remove openssh openssh-server openssh-clients openssh-askpass
# yum package manager
rpm -e --nodeps openssh openssh-server openssh-clients
# apt package manager
apt purge -y openssh-server openssh-client

Install OpenSSL (Optional)#

You can skip this step if your OpenSSL version is compatible with OpenSSH.

Terminal window
tar -zxvf openssl-3.2.4.tar.gz
cd 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 safely
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -sf /usr/local/openssl/include/openssl /usr/include/openssl
# Verify library dependencies
echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/openssl.conf
ldconfig -v | grep -i openssl
# Verify the version
openssl version -a

Install OpenSSH#

Terminal window
tar -zxvf openssh-10.6p1.tar.gz
cd 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 compatibility
ldd /usr/sbin/sshd

Verify the Installation#

Terminal window
openssl version
ssh -V

Modify the sshd Configuration#

Terminal window
vi /etc/ssh/sshd_config
# Write the five configuration lines below
Port 22
ListenAddress 0.0.0.0
PermitRootLogin prohibit-password
PasswordAuthentication no
UsePAM yes

Start the Service#

Terminal window
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!

Sponsor
OpenSSH Security Upgrade Guide: Online and Offline Methods
https://blog.bytesycn.cn/posts/bf5c26f0-e5a4-4794-8b2a-b0cc90961a51/
Author
Ryan Zhang
Published at
2025-09-24

Comments

Profile Image of the Author
Ryan Zhang
Keep building, keep thinking, keep creating.
Announcement
Welcome to my blog!
Categories
Tags
Latest Moments
Site Statistics
Posts
30
Categories
7
Tags
42
Total Words
117,260
Running Days
0 days
Last Activity
0 days ago
Table of Contents