CentOS7下制作OpenSSH 8.4p1 RPM包_centos

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_02


CentOS7下制作OpenSSH 8.4p1 RPM包

1、准备条件

1)openssh-8.4p1.tar.gz源码包

https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_03

(图片可放大查看)

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_04

(图片可放大查看)

2)x11-ssh-askpass-1.2.4.1.tar.gz 源码包

wget https://src.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz/8f2e41f3f7eaa8543a2440454637f3c3/x11-ssh-askpass-1.2.4.1.tar.gz

CentOS7下制作OpenSSH 8.4p1 RPM包_rpm包_05

(图片可放大查看)

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_06

(图片可放大查看)

2、rpm-build以及编译打包环境搭建

yum install rpm-build zlib-devel openssl-devel gcc perl-devel pam-devel

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_07

(图片可放大查看)

mkdir -p /root/rpmbuild/SOURCES
mkdir -p /root/rpmbuild/SPECS
cp /root/openssh-8.4p1.tar.gz /root/rpmbuild/SOURCES/
cp /root/x11-ssh-askpass-1.2.4.1.tar.gz /root/rpmbuild/SOURCES/
tar -zxf openssh-8.4p1.tar.gz -C /opt
cp /opt/openssh-8.4p1/contrib/redhat/openssh.spec /root/rpmbuild/SPECS/
chown sshd:sshd /root/rpmbuild/SPECS/openssh.spec

CentOS7下制作OpenSSH 8.4p1 RPM包_rpm包_08

(图片可放大查看)

3、修改openssh.spec 并进行打包

vi openssh.spec

将原先openssh.spec中的

%global no_x11_askpass 0

%global no_gnome_askpass 0 

修改为

%global no_x11_askpass 1 

%global no_gnome_askpass 1

CentOS7下制作OpenSSH 8.4p1 RPM包_rpm包_09

(图片可放大查看)

并注释掉#BuildRequires: openssl-devel < 1.1 

因为openssl安装的版本都低于1.1 

CentOS7下制作OpenSSH 8.4p1 RPM包_centos_10

(图片可放大查看)

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_11

(图片可放大查看)

这时就可以rpmbuild打包了

rpmbuild -ba openssh.spec

打包开始和打包完成时的截图如下 

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_12

(图片可放大查看)

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_13

(图片可放大查看)

4、压缩并下载生成的rpm包

cd /root/rpmbuild/RPMS/x86_64
ll
tar -zcvf openssh-8.4p1_rpm_package.tar.gz *.rpm
sz openssh-8.4p1_rpm_package.tar.gz

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_14

(图片可放大查看)

5、升级openssh 8.4p1进行验证

在另外一台CentOS7.6机器上升级openssh版本 

升级前的版本openssh7.4p1

CentOS7下制作OpenSSH 8.4p1 RPM包_rpm包_15

(图片可放大查看)

1)上传解压openssh-8.4p1_rpm_package.tar.gz

cd /opt
tar -zxvf openssh-8.4p1_rpm_package.tar.gz

 解压出来的如下4个rpm

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_16

(图片可放大查看)

openssh-8.4p1-1.el7.x86_64.rpm    
openssh-clients-8.4p1-1.el7.x86_64.rpm
openssh-server-8.4p1-1.el7.x86_64.rpm
openssh-debuginfo-8.4p1-1.el7.x86_64.rpm

2)备份配置后rpm -Uvh升级到openssh8.4p1

mkdir /etc/sshconfig_backup
cp /etc/ssh/sshd_config /etc/sshconfig_backup/
cp /etc/pam.d/sshd /etc/sshconfig_backup/pam.d_sshd

rpm -Uvh openssh*.rpm进行手动升级

rpm -Uvh openssh*.rpm

3)还原配置文件

cp /etc/sshconfig_backup/sshd_config /etc/ssh/sshd_config 
cp /etc/sshconfig_backup/pam.d_sshd /etc/pam.d/sshd并加上PermitRootLogin yes允许root用户登录sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/g" /etc/ssh/sshd_config
cat /etc/ssh/sshd_config | grep PermitRootLogin删除/etc/ssh/目录下相关key文件,否则重启sshd服务会报错rm -rf /etc/ssh/ssh_host_*
service sshd restart

CentOS7下制作OpenSSH 8.4p1 RPM包_公众号_17

(图片可放大查看)

4)验证openssh版本信息

ssh -V
rpm -qa | grep openssh

如下图所示说明升级成功 

CentOS7下制作OpenSSH 8.4p1 RPM包_centos_18

(图片可放大查看)

注意openssh8.4p1 rpm包所使用的openssl为1.0.2k版本

公众号后台回复【openssh】下载CentOS7版本的openssh8.4p1版本rpm包