参考:

http://www.2cto.com/os/201510/445119.html

http://www.cnblogs.com/jyzhao/p/5817199.html#2

本文参考以上两位大神的博客,结合实际安装所遇到的问题编写。

一、准备工作

-操作系统:

centos6.5 64位

-升级前版本:

[root@localhost ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@localhost ~]# ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb2013

-升级后版本:

openssl-1.0.2j.tar.gz
openssh-7.3p1.tar.gz

-备份ssh配置文件:

[root@localhost ~]# tar zcvf/etc/ssh.tar.gz /etc/ssh/
tar: 从成员名中删除开头的“/”
/etc/ssh/
/etc/ssh/ssh_host_dsa_key
/etc/ssh/ssh_host_dsa_key.pub
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_config
/etc/ssh/ssh_host_key.pub
/etc/ssh/moduli
/etc/ssh/ssh_host_key
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/sshd_config

-如果系统没有其他用户,新建一个普通用户

[root@localhost ~]# useradd u1
[root@localhost ~]# passwd u1
更改用户 u1 的密码 。
新的 密码:
无效的密码: WAY 过短
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

-将源码包上传至服务器/usr/src目录下

[root@localhost src]# ll /usr/src/
总用量 6680
drwxr-xr-x. 2 root root    4096 9月  23 2011 debug
drwxr-xr-x. 3 root root    4096 9月  25 19:35 kernels
-rw-r--r--. 1 root root 1522617 12月  2 12:14 openssh-7.3p1.tar.gz
-rw-r--r--. 1 root root 5307912 12月  2 12:46openssl-1.0.2j.tar.gz

 

 

二、升级OpenSSL,并删除老版本

1、删除旧版本
[root@localhost src]# rpm -qa | grepopenssl
openssl-1.0.1e-15.el6.x86_64
openssl-devel-1.0.1e-15.el6.x86_64
[root@localhost src]# rpm -e `rpm -qa |grep openssl` --allmatches –nodeps
[root@localhost src]# openssl version
-bash: /usr/bin/openssl: 没有那个文件或目录
2、安装openssl

-参考:

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssl.html

-解包:

[root@localhost src]# tar zxfopenssl-1.0.2j.tar.gz
[root@localhost src]# cd openssl-1.0.2j

-配置,编译

[root@localhost openssl-1.0.2j]# ./config--prefix=/usr         \
>          --openssldir=/etc/ssl \
>          --libdir=lib          \
>          shared                \
>          zlib-dynamic &&
> make depend           &&
> make
-安装:
[root@localhost openssl-1.0.2j]# makeMANDIR=/usr/share/man MANSUFFIX=ssl install &&
> install -dv -m755/usr/share/doc/openssl-1.0.2j  &&
> cp -vfr doc/*     /usr/share/doc/openssl-1.0.2j
3、创建符号链接
[root@localhost openssl-1.0.2j]# ll/usr/lib64 | grep libssl.so.10
[root@localhost openssl-1.0.2j]# ll/usr/lib64 | grep libcrypto.so.10
[root@localhost openssl-1.0.2j]# ln -s/usr/src/openssl-1.0.2j/libssl.so.1.0.0 /usr/lib64/libssl.so.10
[root@localhost openssl-1.0.2j]# ln -s/usr/src/openssl-1.0.2j/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.10
[root@localhost openssl-1.0.2j]# ldconfig
4、验证版本
[root@localhost openssl-1.0.2j]# opensslversion
OpenSSL 1.0.2j  26 Sep 2016

 

三、升级openssh,并删除老版本

-参考:

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.html

1、准备工作
[root@localhost openssh-7.3p1]# install  -v -m700 -d /var/lib/sshd &&
> chown    -v root:sys /var/lib/sshd &&
>
> groupadd -g 50 sshd        &&
> useradd  -c 'sshd PrivSep' \
>          -d /var/lib/sshd  \
>          -g sshd           \
>          -s /bin/false     \
>          -u 50 sshd
2、配置、编译

-解包

[root@localhost src]# tar zxfopenssh-7.3p1.tar.gz
[root@localhost src]# cd openssh-7.3p1

-配置、编译

[root@localhost openssh-7.3p1]# ./configure--prefix=/usr                     \
>             --sysconfdir=/etc/ssh             \
>             --with-md5-passwords              \
>             --with-privsep-path=/var/lib/sshd&&
> make

-卸载旧版本

[root@localhost openssh-7.3p1]# rpm -qa |grep openssh
openssh-5.3p1-94.el6.x86_64
openssh-askpass-5.3p1-94.el6.x86_64
openssh-clients-5.3p1-94.el6.x86_64
openssh-server-5.3p1-94.el6.x86_64
[root@localhost openssh-7.3p1]# rpm -e `rpm-qa | grep openssh` --nodeps

-安装

[root@localhost openssh-7.3p1]# makeinstall &&
> install -v -m755    contrib/ssh-copy-id /usr/bin     &&
>
> install -v -m644    contrib/ssh-copy-id.1 \
>                     /usr/share/man/man1              &&
> install -v -m755 -d/usr/share/doc/openssh-7.3p1     &&
> install -v -m644    INSTALL LICENCE OVERVIEW README* \
>                    /usr/share/doc/openssh-7.3p1

-验证版本

[root@localhost openssh-7.3p1]# ssh -V
OpenSSH_7.3p1, OpenSSL 1.0.2j  26 Sep 2016

-添加启动脚本

[root@localhost ~]# cp/usr/src/openssh-7.3p1/contrib/redhat/sshd.init /etc/init.d/sshd

-加入开机自启

[root@localhost ~]# chkconfig --add sshd
[root@localhost ~]# chkconfig sshd on
[root@localhost ~]# chkconfig sshd --list
sshd             0:关闭     1:关闭     2:启用     3:启用     4:启用     5:启用     6:关闭

-启动sshd

[root@localhost ~]# service sshd start
Starting sshd:                                             [确定]

 

四、验证

-远程退出重新登录

[root@localhost ~]# exit
logout
[c:\~]$ ssh [email protected]



 

如出现root无法登录

源码包升级ssl/ssh_第1张图片

需要利用其它用户登录修改配置文件

[c:\~]$ ssh [email protected]
Connecting to 192.168.10.151:22...
Connection established.
To escape to local shell, press'Ctrl+Alt+]'.
 
[u1@localhost ~]$ su - root
密码:
[root@localhost ~]#

 

 

-修改sshd_config

[root@localhost ~]# vim/etc/ssh/sshd_config
 
 
# Authentication:
 
 
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
 
[root@localhost ~]# service sshd restart
Stopping sshd:                                             [确定]
Starting sshd:                                             [确定]
[root@localhost ~]# exit
logout
[u1@localhost ~]$ exit
Logout

 

-再次验证

[c:\~]$ ssh [email protected]
 
 
Connecting to 192.168.10.151:22...
Connection established.
To escape to local shell, press'Ctrl+Alt+]'.
 
Last login: Sun Sep 25 20:07:17 2016 from192.168.10.1
[root@localhost ~]# openssl version
OpenSSL 1.0.2j  26 Sep 2016
[root@localhost ~]# ssh -V
OpenSSH_7.3p1, OpenSSL 1.0.2j  26 Sep 2016