centOS升级SSH到OpenSSH_7.5p1

http://www.cnblogs.com/xshrim/p/6472679.html (Redhat 6.7 x64升级SSH到OpenSSH_7.4p1完整文档 )

http://www.linuxidc.com/Linux/2017-05/143568.htm (CentOS 6.6升级OpenSSH到最新版本7.5.p1)

 

 

yum install gcc pam-devel zlib-devel

一、升级原因

7.4以下openssh版本存在严重漏洞:

1.OpenSSH 远程权限提升漏洞(CVE-2016-10010)  

2.OpenSSH J-PAKE授权问题漏洞(CVE-2010-4478)  

3.Openssh MaxAuthTries限制绕过漏洞(CVE-2015-5600)  

OpenSSL>=1.0.1可以不用升级OpenSSL

 

二、安装telnet服务

1、安装软件

1 # yum -y install telnet-server* telnet

 

2、启用telnet服务,先关闭防火墙,否则telnet可能无法连接

# service iptables stop

# chkconfig iptables off

# vim /etc/xinetd.d/telnet 

将其中disable字段的yes改为no以启用telnet服务 

# mv /etc/securetty /etc/securetty.old    #允许root用户通过telnet登录   该/etc/securetty文件作用

# service xinetd start                    #启动telnet服务 

# chkconfig xinetd on                    #使telnet服务开机启动,避免升级过程中服务器意外重启后无法远程登录系统

 

3、测试telnet能否正常登入系统

         控制面板中 程序-启用或关闭windows程序 中打开 Telnet客户端,则在cmd界面中就可以

         telnet ip或者域名  端口号

      C:\Windows\system32>telnet ip 23      #ip为你自己要登录的服务器ip

输入用户名,密码就OK 表示成功了。

       退出telnet命令 ctrl+]  然后在telnet 命令行输入 quit  就可以退出了。

 

三、升级openssL 因为有openssl协议相关的升级,OpenSSL>=1.0.1可以不用升级

故:

1、备份当前openssl; 下载地址https://www.openssl.org/source/old/

# find / -name openssl

/usr/lib64/openssl

/usr/include/openssl

/usr/bin/openssl

/etc/pki/ca-trust/extracted/openssl

 

# mv  /usr/lib64/openssl /usr/lib64/openssl.old

# mv  /usr/include/openssl /usr/include/openssl.old

# mv  /usr/bin/openssl  /usr/bin/openssl.old

# mv  /etc/pki/ca-trust/extracted/openssl  /etc/pki/ca-trust/extracted/openssl.old

 

       如下两个库文件必须先备份,因系统内部分工具(如yum、wget等)依赖此库,而新版OpenSSL不包含这两个库

 

  # cp  /usr/lib64/libcrypto.so.10  /usr/lib64/libcrypto.so.10.old

  # cp  /usr/lib64/libssl.so.10  /usr/lib64/libssl.so.10.old

2、卸载

# rpm -qa | grep openssl

openssl-1.0.1e-42.el6.x86_64

 

# rpm -e --nodeps openssl-1.0.1e-42.el6.x86_64

# rpm -qa | grep openssl

或者直接执行此命令:rpm -qa |grep openssl|xargs -i rpm -e --nodeps {}

3、解压openssl_1.0.1u源码并编译安装

# tar -zxvf openssl-1.0.1u.tar.gz

# cd openssl-1.0.1u

# ./config --prefix=/usr --openssldir=/etc/ssl --shared zlib    #必须加上--shared,否则编译时会找不到新安装的openssl的库而报错

# make

# make test                            #必须执行这一步结果为pass才能继续,否则即使安装完成,ssh也无法使用

# make install

# openssl version -a                   #查看是否升级成功

 

4、恢复共享库

 

       具体执行时请先查看是否新版本,并验证是否生产新的文件;由于新版本OpenSSL不提供libcrypto.so.10和libssl.so.10这两个库,而yum、wget等工具又依赖此库,因此需要将先前备份的这两个库进行恢复,其他的可视情况考虑是否恢复。

# mv  /usr/lib64/libcrypto.so.10.old  /usr/lib64/libcrypto.so.10

# mv  /usr/lib64/libssl.so.10.old  /usr/lib64/libssl.so.10

 

四、升级openSSH,下载页面http://www.openssh.com/portable.html

1、备份当前openssh

    # mv /etc/ssh /etc/ssh.old

2、卸载当前openssh

 

[root@localhost home]#  rpm -qa | grep openssh

openssh-server-5.3p1-122.el6.x86_64

openssh-clients-5.3p1-122.el6.x86_64

openssh-5.3p1-122.el6.x86_64

openssh-askpass-5.3p1-122.el6.x86_64

 

[root@localhost home]# rpm -e --nodeps openssh-server-5.3p1-122.el6.x86_64

[root@localhost home]# rpm -e --nodeps openssh-clients-5.3p1-122.el6.x86_64

[root@localhost home]# rpm -e --nodeps openssh-5.3p1-122.el6.x86_64

[root@localhost home]# rpm -e --nodeps openssh-askpass-5.3p1-122.el6.x86_64

再次查看

[root@localhost home]# rpm -qa | grep openssh    已经卸载完成

 

或者直接执行此命令:rpm -qa |grep openssh|xargs -i rpm -e --nodeps {}

 

注意:卸载过程中如果出现以下错误 

[root@localhost home]# rpm -e --nodeps openssh-server-5.3p1-122.el6.x86_64  

error reading information on service sshd: No such file or directory 

error: %preun(openssh-server-5.3p1-122.el6.x86_64) scriptlet failed, exit status 1 

解决方法: 

# rpm -e --noscripts openssh-server-5.3p1-104.el6.x86_64

 

3、openssh安装前环境配置

 

注意: 必须备份 /etc/pam.d/sshd

# mv /etc/pam.d/sshd /etc/pam.d/sshd.old

不备份,否则最后登录不上的。

 

# install -v -m700 -d /var/lib/sshd

# chown -v root:sys /var/lib/sshd

当前系统sshd用户已经存在的话以下不用操作 

# groupadd -g 50 sshd

# useradd  -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd

 

4、解压openssh_7.5p1源码并编译安装

 

[root@localhost home]# tar -zxvf openssh-7.5p1.tar.gz

[root@localhost home]# cd openssh-7.5p1

[root@localhost openssh-7.5p1]# ./configure --prefix=/usr  --sysconfdir=/etc/ssh  --with-md5-passwords  --with-pam  --with-zlib --with-openssl-includes=/usr --with-privsep-path=/var/lib/sshd

[root@localhost openssh-7.5p1]# make

[root@localhost openssh-7.5p1]# make install

 

5、openssh安装后环境配置

 

 在openssh编译目录执行如下命令

[root@localhost openssh-7.5p1]# install -v -m755    contrib/ssh-copy-id /usr/bin

[root@localhost openssh-7.5p1]# install -v -m644    contrib/ssh-copy-id.1 /usr/share/man/man1

[root@localhost openssh-7.5p1]# install -v -m755 -d /usr/share/doc/openssh-7.5p1

[root@localhost openssh-7.5p1]# install -v -m644    INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.5p1

[root@localhost openssh-7.5p1]# ssh -V              #验证是否升级成功

 OpenSSH_7.5p1, OpenSSL 1.0.1e-fips 11 Feb 2013

     因我本身没更新openssl版本原因

6、启用OpenSSH服务

 

 在openssh编译目录执行如下目录

[root@localhost openssh-7.5p1]# echo 'X11Forwarding yes' >> /etc/ssh/sshd_config

[root@localhost openssh-7.5p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config  

                                     #允许root用户通过ssh登录

[root@localhost openssh-7.5p1]# cp -p contrib/redhat/sshd.init /etc/init.d/sshd

注意: 这一操作很重要!很重要!很重要!重要的事情说三遍,因为openssh安装好默认是不执行sshd_config文件的,所以即使在sshd_config中配置允许root用户远程登录,但是不加上这句命令,还是不会生效!

vim /etc/init.d/sshd

在 ‘$SSHD $OPTIONS && success || failure’这一行上面加上一行 OPTIONS="-f /etc/ssh/sshd_config"

保存退出

 

[root@localhost openssh-7.5p1]# chmod +x /etc/init.d/sshd

[root@localhost openssh-7.5p1]# chkconfig  --add  sshd                      #加入系统服务

[root@localhost openssh-7.5p1]# chkconfig  sshd  on                           #自启动

[root@localhost openssh-7.5p1]# chkconfig  --list  sshd                       #查看系统启动服务是否增加改项

sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@localhost openssh-7.5p1]# service sshd start

注意:这里必须先检查/etc/pam.d/下没有生成的有 sshd还原 /etc/pam.d/sshd 文件才行;

[root@localhost openssh-7.5p1]# mv /etc/pam.d/sshd.old /etc/pam.d/sshd

 

五、善后工作

 

    新开启远程终端以ssh [ip]登录系统,确认一切正常升级成功后,只需关闭telnet服务以保证系统安全性即可。

# mv /etc/securetty.old /etc/securetty

# chkconfig  xinetd off

# service xinetd stop

 

  如有必要,可重新开启防火墙

  # service iptables start

  # chkconfig iptables on

 

    此时可以直接登录了;有时新版本升级后,在xshell客户端相关中链接出现找不到匹配的outgoing encryption算法(No matching outgoing encryption algorithm found);设置下客户端工具的编码方式即可,网上自己查阅;但如需还原之前的ssh配置信息,可直接删除升级后的配置信息,恢复备份。

# rm -rf /etc/ssh

# mv /etc/ssh.old /etc/ssh

 

 注意:我操作的时候,发现 /etc/pam.d/ 目录下的 sshd 文件不存在了,后来拷贝了一个别的系统的过来才能登录;并且还原/etc/securetty文件才行。一旦该文件,则telnet 就不能登录了。 故建议采用dropbear 第3方工具来操作。

 

猜你喜欢

转载自yjph83.iteye.com/blog/2390800