centos7做openssh8.x rpm包
1、rpm-build以及编译打包环境搭建
yum install rpm-build zlib-devel openssl-devel gcc perl-devel pam-devel
2、创建rpm构建目录,下载所需源码包到source并解压
wget https://cdn.openbsd.org/pub/openbsd/openssh/portable/openssh-8.7p1.tar.gz
wget https://src.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz
mkdir -p /root/rpmbuild/sources
mkdir -p /root/rpmbuild/specs
cp /root/openssh-8.7p1.tar.gz /root/rpmbuild/sources/
cp /root/x11-ssh-askpass-1.2.4.1.tar.gz /root/rpmbuild/sources/
cd /root/rpmbuild/sources/
tar -zxvf openssh-8.7p1.tar.gz
*复制出需要的spec编译文件*
cp /root/rpmbuild/sources/openssh-8.7p1/contrib/redhat/openssh.spec /root/rpmbuild/specs/
修改文件参数
vim /root/rpmbuild/specs/openssh.spec
将原先openssh.spec中的
%global no_x11_askpass 0
%global no_gnome_askpass 0
修改为
%global no_x11_askpass 1
%global no_gnome_askpass 1
或者执行
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
注释掉#buildrequires: openssl-devel < 1.1
因为openssl安装的版本都低于1.1
cd /root/rpmbuild/specs
3、rpmbuild打包
rpmbuild -ba openssh.spec # -ba参数,建立源码和二进制包
生成的rpm包在/root/rpmbuild/rpms/x86_64目录下
cd /root/rpmbuild/rpms/x86_64
4、下面来测试安装下 写了个脚本
脚本内容
[root@localhost openssh-8.7p1]# cat update.sh
#!/bin/bash
cp -ar /etc/ssh{,.bak_KaTeX parse error: Expected group after '_' at position 40: …am.d/sshd{,.bak_̲(date +%F)}
yum localinstall .rpm -y
mv /etc/ssh{,.v8.7.rpmnew}
mv /etc/pam.d/sshd{,.v8.7.rpmnew}
mv /etc/ssh.bak_KaTeX parse error: Expected group after '_' at position 43: …/pam.d/sshd.bak_̲(date +%F) /etc/pam.d/sshd
chmod 600 /etc/ssh/
echo ‘change before:’
grep PermitRootLogin /etc/ssh/sshd_config
sed -i ‘s/#PermitRootLogin/PermitRootLogin/’ /etc/ssh/sshd_config
echo ‘change after:’
grep PermitRootLogin /etc/ssh/sshd_config
echo “KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1” >> /etc/ssh/sshd_config
systemctl restart sshd
sh update.sh
验证openssh版本信息
ssh -v
rpm -qa | grep openssh
打包压缩 tar -zcvf openssh-8.7p1.tar.gz openssh-8.7p1/
解压缩 tar -zxvf openssh-8.7p1.tar.gz