1.下载依赖

yum install -y wget gcc pam-devel libselinux-devel zlib-devel openssl-devel

2.下载openssh9.3

wget -O openssh.tar.gz https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz

3.备份原配置文件

cp /etc/ssh/sshd_config sshd_config.backup
cp /etc/pam.d/sshd sshd.backup

4.删除旧版本

rpm -e --nodeps `rpm -qa | grep openssh`

5.解压新版本

tar -zxvf openssh.tar.gz 
cd openssh-9.3p1

6.编译配置

./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl --without-hardening 
注:如openssl是通过编译安装,请改为实际安装目录

7.编译安装

make && make install

8.调整文件权限

chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key

9.复制配置文件

cp -a contrib/redhat/sshd.init /etc/init.d/sshd
chmod u+x /etc/init.d/sshd

10.还原 原配置文件

mv ../sshd.backup /etc/pam.d/sshd
mv ../sshd_config.backup /etc/ssh/sshd_config

11.添加自启动

chkconfig --add sshd
chkconfig sshd on

12.重启服务

systemctl restart sshd

13.验证结果

#openssh版本显示9.3即成功 
ssh -V
https://zhuanlan.zhihu.com/p/522701378?utm_id=0