准备工作
下载源码包、创建rpm包制作所需相关的目录
开始rpm制作
1、检查本机openssh版本,查看yum源中最新的版本
ssh -V
yum info openssh
2、建立目录下载源码包
cd /opt
mkdir -pv openssh/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz -O openssh/SOURCES/openssh-7.5p1.tar.gz
#下载x11支持包
wget http://pkgs.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz/8f2e41f3f7eaa8543a2440454637f3c3/x11-ssh-askpass-1.2.4.1.tar.gz -O openssh/SOURCES/x11-ssh-askpass-1.2.4.1.tar.gz
3、开始制作
cd openssh/SOURCES
tar xf openssh-7.5p1.tar.gz
cp openssh-7.5p1/contrib/redhat/openssh.spec ../SPECS
修改编译配置文件
#进入文件夹
cd ../SPECS/
#按需修改以下内容:
# Do we want to disable building of x11-askpass? (1=yes 0=no)
%define no_x11_askpass 1
# Do we want to disable building of gnome-askpass? (1=yes 0=no)
%define no_gnome_askpass 1
使用rpmbuild制作rpm包,完成后在RPMS下生成rpm安装包
rpmbuild -bb openssh.spec
4、上传rpm包到服务器进行安装 ,安装前备份配置文件,以免被覆盖
yum -y install ./openssh*.rpm
# 或者使用
rpm -ivh *.rpm
以下是使用脚本进行安装升级的操作
mkdir /opt/backup
mv /etc/ssh /opt/backup
cp /etc/pam.d/sshd /opt/backup/sshd.pam
yum -y install ./openssh*.rpm
mv /etc/ssh/sshd_config{,.old_$(date '+%s')}
cat > /etc/ssh/sshd_config << SSHDEOF
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
Subsystem sftp /usr/libexec/openssh/sftp-server
SSHDEOF
mv /etc/pam.d/sshd{,.old_$(date '+%s')}
cp /opt/backup/sshd.pam /etc/pam.d/sshd
service sshd restart