1、yum安装编译依赖的组件
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
虚拟机配置可参考本地yum源
2、建立编译目录
mkdir -pv /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
3、源码包下载到/root/rpmbuild/SOURCES
wget http://mirror.aarnet.edu.au/pub/OpenBSD/OpenSSH/portable/openssh-8.9p1.tar.gz -O /root/rpmbuild/SOURCES/openssh-8.9p1.tar.gz
4、解压spec编译文件
cd /root/rpmbuild/SOURCES/ tar -xf openssh-8.9p1.tar.gz openssh-8.9p1/contrib/redhat/openssh.spec mv openssh-8.9p1 /root/rpmbuild/SPECS
5、配置spec编译文件
a、不生成askpass包
b、解决openssl-devel < 1.1报错
cd /root/rpmbuild/SPECS/openssh-8.9p1/contrib/redhat/ 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 sed -i '/openssl-devel < 1.1/s/^/#/' openssh.spec
6、编译openssh源码
rpmbuild -bb /root/rpmbuild/SPECS/openssh-8.9p1/contrib/redhat/openssh.spec
编译最后无报错即编译成功
7、查看编译的RPM文件
在/root/rpmbuild/RPMS/x86_64/
附:openssh升级
1、先将本机telnet服务打开,避免升级后ssh服务挂掉
2、关闭selinux
3、安装/root/rpmbuild/RPMS/x86_64/下三个rpm包
4、升级完后,更改ssh下面的key文件权限。不然重启ssh提示报错
chmod 600 /etc/ssh/ssh_host*key
5、重启sshd,查看sshd状态,显示绿色running即可升级成功,关闭telnet服务。
ps:rpmbuild提示下面问题
1、install: cannot stat `contrib/redhat/sshd.pam.old': No such file or directory
解决:下载8.4的包,提取contrib/redhat sshd.pam.old sshd.init.old加到openssh 8.9p1