系统版本为RHEL7如下


cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 4.2 (Maipo)


1、在官网下载tar包


(1)openssh-7.7p1的下载

官网地址:http://www.openssh.com/portable.html

文件名称:openssh-7.7p1.tar.gz


(2)安装的过程中需要x11-ssh-askpass-1.2.4.1.tar.gz,下载地址如下:


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或者http://ftp.riken.jp/Linux/momonga/6/Everything/SOURCES/x11-ssh-askpass-1.2.4.1.tar.gz


(3)使用ftp的方式传到Linux主机上。


ftp 主机ip输入账号密码binarycd 对应的文件夹mget *.* 下载相关的文件后退出quit


2、系统要求


(1)查看tar包里面的INSTALL文件,有要求

Zlib 1.1.4 or 1.2.1.2 or greater (earlier 1.2.x versions have problems):

libcrypto (LibreSSL or OpenSSL >= 1.0.1 < 1.1.0)


(2)通过rpm -q zlib-devel查询版本号。

3、必要软件的安装

因我的系统有些包没有安装,为了解决依赖问题,我选择使用光盘iso文件内的RPMS进行yum安装。


(1)挂载iso文件。


mount /data/iso/rhel-server-7.2-x86_64-dvd.iso /mnt/dvd/


(2)yum 安装需要的包


yum install openssl-devel.x86_64 yum install krb5-devel.x86_64


4、打包Openssh7.7p1


(1)创建文件,解压缩


mkdir -p /usr/src/redhat/{SOURCES,SPECS}cd /usr/src/redhat/SOURCES/tar xf openssh-7.7p1.tar.gzcp openssh-7.7p1/contrib/redhat/openssh.spec /usr/src/redhat/SPECS/chown sshd:sshd /usr/src/redhat/SPECS/ -Rcp /usr/src/redhat/SOURCES/openssh-7.7p1.tar.gz ~/rpmbuild/SOURCES/cd /usr/src/redhat/SPECS/


(2)然后进入到vi /usr/src/redhat/SPECS/openssh.spec,找到11-15行


# Do we want to disable building of x11-askpass? (1=yes 0=no)%define no_x11_askpass 0# Do we want to disable building of gnome-askpass? (1=yes 0=no)%define no_gnome_askpass 0


将0修改为1,即


# 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

(3)将下载的x11-ssh-askpass-1.2.4.1.tar.gz复制到/root/rpmbuild/SOURCES/文件内


cp x11-ssh-askpass-1.2.4.1.tar.gz /root/rpmbuild/SOURCES/

(4)打包


rpmbuild -ba openssh.spec

发现错误。提示我的openssl-devel < 1.1的条件不满足。实际查询版本为1.0.1e满足条件。所以从openssh.spec里面103行删除该判断条件


BuildRequires: openssl-devel < 1.1

删除上面一行判断条件后继续打包。无提示错误。

(5)查看生成的rpm包。


cd /root/rpmbuild/RPMS/x86_64/

通过ls可以看到已经生成如下包


openssh-7.7p1-1.el6.x86_64.rpmopenssh-clients-7.7p1-1.el6.x86_64.rpmopenssh-debuginfo-7.7p1-1.el6.x86_64.rpmopenssh-server-7.7p1-1.el6.x86_64.rpm


5、安装telnet并测试ssh。因为之前已经使用过telnet,这里直接启动服务。防火墙已经关闭。不需要设置。


systemctl start xinetdsystemctl start telnet.socket



6、通过telnet登录主机,然后执行


rpm -Uvh *.*

通过rpm -q 查看版本已经升级成功


7、测试ssh登录,发现无法登录。

(1)使用systemctl status sshd.service

发现报错如下:


PAM unable to dlopen(/lib64/security/pam_stack.so): /lib64/security/pam_stack.so: cannot open shared   file: No such file or directoryPAM adding faulty module: /lib64/security/pam_stack.so

经过排查发现是ssh rpm 升级后会修改/etc/pam.d/sshd 文件,如下:


#%PAM-1.0auth       required     pam_stack.so service=system-authaccount    required     pam_nologin.soaccount    required     pam_stack.so service=system-authpassword   required     pam_stack.so service=system-authsession    required     pam_stack.so service=system-auth

修改为之前的即可。修改后的文件如下:


#%PAM-1.0auth       required     pam_sepermit.soauth       include      password-authaccount    required     pam_nologin.soaccount    include      password-authpassword   include      password-auth# pam_selinux.so close should be the first session rulesession    required     pam_selinux.so closesession    required     pam_loginuid.so# pam_selinux.so open should only be followed by sessions to be executed in the user contextsession    required     pam_selinux.so open env_paramssession    optional     pam_keyinit.so force revokesession    include      password-auth

(2)还可能出现权限的报错

使用chown sshd:sshd 文件,修改文件权限即可。

8、结尾工作


(1)关闭telnet


systemctl stop xinetdsystemctl stop telnet.socket


(2)确认sshd服务


chkconfig发现服务已经ON如果没有ON可以用chkconfig sshd on 开启

(3)卸载光盘


unmount /mnt/dvd/












收藏 打印