在 CentOS 上升级 OpenSSH 版本,常见有 三种方式,按推荐程度说明。
⚠️ 升级 SSH 有风险,操作前务必确认有控制台/带外管理权限,避免被踢出服务器。
适用于 CentOS 7 / 8 / Stream。
ssh -V
yum update openssh -y
dnf update openssh -y
升级完成后重启 SSH:
systemctl restart sshd
✅ 优点:安全、简单、不会破坏系统
❌ 缺点:版本可能不是最新,而是系统维护版本
适合需要 较新 OpenSSH 但又不想手动编译。
yum install -y epel-release
yum info openssh
yum update openssh -y
systemctl restart sshd
⚠️ 生产环境慎用
yum groupinstall "Development Tools" -y
yum install -y gcc openssl-devel pam-devel zlib-devel
dnf groupinstall "Development Tools" -y
dnf install -y gcc openssl-devel pam-devel zlib-devel
(示例为 9.6p1,请到官网确认最新版)
cd /usr/local/src
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.6p1.tar.gz
tar -zxvf openssh-9.6p1.tar.gz
cd openssh-9.6p1
./configure \
--prefix=/usr \
--sysconfdir=/etc/ssh \
--with-pam \
--with-zlib \
--with-ssl-engine
make
make install
systemctl restart sshd
✅ 查看新版本:
ssh -V
⚠️ 注意
/etc/sshcp -r /etc/ssh /etc/ssh.bak
cp /etc/pam.d/sshd /etc/pam.d/sshd.bak
确保:
/etc/ssh/sshd_configPermitRootLogin、PasswordAuthenticationjournalctl -u sshd -xe
| 场景 | 推荐方式 |
|---|---|
| 生产服务器 | ✅ 系统仓库升级 |
| 需要较新版本 | ✅ EPEL / 官方仓库 |
| 最新特性 | ⚠️ 手动编译 |
如果你愿意,可以告诉我:
我可以给你 最安全、最合适的升级方案。