以下步骤在联网的Centos 7环境下执行
1、 下载用于编译openssh的rpm包的工具
yum install -y rpm-build gcc gcc-c++ glibc glibc-devel openssl-devel openssl prce pcre-devel zlib zlib-devel make wget krb5-devel pam-devel libX11-devel xmkmf libXt-devel initscripts libXt-devel imake gtk2-devel lrzsz --downloadonly --downloaddir=/opt/software/package/rpm-build
2、安装编译openssh的rpm包的工具
rpm -Uvh --force --nodeps /opt/software/package/rpm-build/*.rpm
3、创建编译目录,注意!!!必须该目录,不要修改路径
mkdir -pv /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
4、下载源码包到指定位置,注意!!!不能下载到其他地方
官网查看新版本:http://www.openssh.com/
下载地址:https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
cd /root/rpmbuild/SOURCES/
curl -O https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.2p1.tar.gz
5、解压specs文件到指定目录
tar -zxvf openssh-9.2p1.tar.gz -C /root/rpmbuild/SPECS/
cd /root/rpmbuild/SPECS/openssh-9.2p1/contrib/redhat/
6、修改openssh.spec文件防止编译报错
#不生成askpass包
sed -i -e "s/%global no_gnome_askpass 0/%global no_gnome_askpass 1/g" openssh.spec
sed -i -e "s/%global no_x11_askpass 0/%global no_x11_askpass 1/g" openssh.spec
#解决openssl-devel < 1.1报错
sed -i '/openssl-devel < 1.1/s/^/#/' openssh.spec
7、编译openssh的rpm包
rpmbuild -bb /root/rpmbuild/SPECS/openssh-9.2p1/contrib/redhat/openssh.spec
cd /root/rpmbuild/RPMS/x86_64/
8、传输文件到指定服务器,注意!!!删除openssh-debuginfo-*.rpm包,该包不用安装