Chinaunix首页 | 论坛 | 博客
  • 博客访问: 330716
  • 博文数量: 30
  • 博客积分: 3021
  • 博客等级: 少校
  • 技术积分: 408
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-01 11:32
文章分类

全部博文(30)

文章存档

2022年(1)

2015年(2)

2014年(1)

2013年(1)

2012年(2)

2011年(2)

2010年(3)

2009年(10)

2008年(8)

分类: LINUX

2015-07-14 11:05:02

CentOS 5.X自带的OpenSSH版本很低,还是4.3P2的,不支持SFTP Chroot功能,而且一些漏洞扫描工具会根据版本号报出openssh漏洞,加上之前的心脏出血漏洞,也有升级OpenSSL的需求。
因此,特总结了以下三种升级到新版本的方法:

实际操作中如果提前将自动超时取消(执行 export TMOUT=0),并在未最终升级完openssh前不重启ssh服务,一般都不会断开远程ssh连接。
为了升级安全,可先启用telnet服务,默认系统是没有启用这个服务的。
启用Telnet远程管理

点击(此处)折叠或打开

  1. vi /etc/xinetd.d/krb5-telnet 
    # default: off
    # description: The kerberized telnet server accepts normal telnet sessions, \
    #              but can also use Kerberos 5 authentication.
    service telnet
    {
            flags           = REUSE
            socket_type     = stream        
            wait            = no
            user            = root
            server          = /usr/kerberos/sbin/telnetd
            log_on_failure  += USERID
            disable         = no
    }
修改disable为no,默认为yes,即禁用telnet服务。修改为no,即表示启用telnet服务。
重启xinetd,开启Telnet服务,如果没有安装xinetd的话,需要先进行安装 

点击(此处)折叠或打开

  1. yum install xinetd
  2. yum install telnet-server
然后重启服务

点击(此处)折叠或打开

  1. service xinetd restart
检查Telnet是否正常启动

点击(此处)折叠或打开

  1. netstat -tnlp | grep :23
注意:为了安全,Telnet是不能以root直接登陆的,以普通用户登录后再su切换root,SSH升级成功后,记得关闭telnet服务。


方法一:源码包编译安装

点击(此处)折叠或打开

  1. wget
  2. tar xvf openssh-6.9p1.tar.gz
  3. cd openssh-6.9p1
  4. ./configure --prefix=/usr --sysconfdir=/etc/ssh
  5. make
  6. make install
上面的方法会覆盖原版本的文件,make install覆盖/etc/ssh下配置文件时可能会报错,这时把/etc/ssh下的原配置文件备份并删除,再make install一次就可以了。
建议安装还是换个路径比较好,特别是线上服务器。下面给出的是官方给出的几种方案,根据自己情况调整吧!

点击(此处)折叠或打开

  1. To install OpenSSH with default options:
  2. ./configure
  3. make
  4. make install
  5. This will install the OpenSSH binaries in /usr/local/bin, configuration files
  6. in /usr/local/etc, the server in /usr/local/sbin, etc. To specify a different
  7. installation prefix, use the --prefix option to configure:
  8. ./configure --prefix=/opt
  9. make
  10. make install
  11. Thsi will install OpenSSH in /opt/{bin,etc,lib,sbin}. You can also override
  12. specific paths, for example:
  13. ./configure --prefix=/opt --sysconfdir=/etc/ssh
  14. make
  15. make install
  16. This will install the binaries in /opt/{bin,lib,sbin}, but will place the
  17. configuration files in /etc/ssh.

方法二:编译RPM包安装

此安装方法分两步骤,首先要升级openssl新版本,然后才可以正常安装openssh新版本,具体如下:

a) 升级openssl版本

注意:我的实际环境是CentOS5.3和RedHat 5.5及RedHat 5.9版本,openssh和openssl的版本分别是OpenSSH_4.3p2, OpenSSL 0.9.8e,
直接编译生成openssh-6.8p1-1.i386.rpm相关包的时候会报错,提示需要openssl 0.9.8f以后的版本,因此需要首先升级openssl的版本,最初直接升级到openssl官方最新版本openssl-1.0.2d.tar.gz,实际操作中发现tar包编译的方式可以升级,生成rpm包安装的话,在强制安装完openssl-1.0.2d-1.i386.rpm最新的rpm包后,执行ssh -V的时候报“ssh: error while loading shared libraries: libcrypto.so.0.9.8: cannot open shared object file: No such file or directory”,而安装openssl-1.0.2d-1.i386.rpm后生成的是libcrypto.so.1.0.0,即使强制用libcrypto.so.1.0.0做了libcrypto.so.0.9.8的软链接也不起作用,所以CentOS 5的操作系统最后使用openssl 0.9.8的最终版本。
最终选择了安装openssl-0.9.8zg版本,升级过程记录如下:

点击(此处)折叠或打开

  1. wget
  2. cp openssl-0.9.8zg.tar.gz /usr/src/redhat/SOURCES/
  3. tar xvf openssl-0.9.8zg.tar.gz
  4. cp openssl-0.9.8zg/openssl.spec /usr/src/redhat/SPECS/
  5. rpmbuild /usr/src/redhat/SPECS/openssl.spec
  6. cd /usr/src/redhat/RPMS/i386/
  7. ls -l
  8. -rw-r--r-- 1 root root 1219140 06-24 11:22 openssl-0.9.8zg-1.i386.rpm
  9. -rw-r--r-- 1 root root 118129 06-24 11:22 openssl-debuginfo-0.9.8zg-1.i386.rpm
  10. -rw-r--r-- 1 root root 2187227 06-24 11:22 openssl-devel-0.9.8zg-1.i386.rpm
  11. -rw-r--r-- 1 root root 608743 06-24 11:22 openssl-doc-0.9.8zg-1.i386.rpm
注意:此步骤中,如果操作系统为x86_64时,需要首先修改openssl.spec里面的/usr/lib为/usr/lib64,然后再进行rpmbuild,如果不修改,相关的so文件会自动安装到32位操作系统对应的/usr/lib下,而不是64位操作系统应该对应的/usr/lib64下,修改方法如下:
在openssl.spec原文件的基础上对应增加以下对操作版本判断的语句,

点击(此处)折叠或打开

  1. %ifarch i386 i486 i586 i686
  2. %attr(0755,root,root) /usr/lib/*.so*
  3. %attr(0755,root,root) /usr/lib/engines/*.so*
  4. %endif
  5. %ifarch x86_64
  6. %attr(0755,root,root) /usr/lib64/*.so*
  7. %attr(0755,root,root) /usr/lib64/engines/*.so*
  8. %endif
  9. ................
  10. %ifarch i386 i486 i586 i686
  11. %attr(0644,root,root) /usr/lib/*.a
  12. %attr(0644,root,root) /usr/lib/pkgconfig/
  13. %endif
  14. %ifarch x86_64
  15. %attr(0644,root,root) /usr/lib64/*.a
  16. %attr(0644,root,root) /usr/lib64/pkgconfig/
  17. %endif
我已经改好了openssl-0.9.8zg和openlssl-1.0.2d两个版本的spec文件,可以用来直接使用,生成文件的路径按照操作系统原生iso文件里rpm包生成文件的路径进行了对应修改。详见附件。
openssl.spec

安装新版openssl

点击(此处)折叠或打开

  1. rpm -Uvh openssl-0.9.8zg-1.i386.rpm openssl-devel-0.9.8zg-1.i386.rpm
此时报了一系列的现有软件的包依赖,如下:
perl(WWW::Curl::Easy) is needed by openssl-1.0.2d-1.i386
libcrypto.so.6 is needed by (installed) openldap-2.3.43-3.el5.i386
libcrypto.so.6 is needed by (installed) curl-7.15.5-2.el5.i386
libcrypto.so.6 is needed by (installed) m2crypto-0.16-6.el5.3.i386
libcrypto.so.6 is needed by (installed) openssh-4.3p2-29.el5.i386
................
libssl.so.6 is needed by (installed) wget-1.11.4-3.el5_8.2.i386
libssl.so.6 is needed by (installed) openssl-devel-0.9.8e-7.el5.i386
openssl = 0.9.8e-7.el5 is needed by (installed) openssl-devel-0.9.8e-7.el5.i386[/quote]
解决办法是用nodeps参数强制安装:

点击(此处)折叠或打开

  1. rpm --nodeps -Uvh openssl-0.9.8zg-1.i386.rpm openssl-devel-0.9.8zg-1.i386.rpm
或者先卸载已有的openssl包,然后再安装,不卸载直接升级安装的话会报”ldconfig: /lib/libssl.so.0.9.8 is not a symbolic link,ldconfig: /lib/libcrypto.so.0.9.8 is not a symbolic link“的错误,卸载后再安装就不会报这个错误。
64位的机器上可以同时安装有x86_64和i386两个版本的openssl,先查询已安装的包
rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" openssl 
再逐个卸载
rpm -e --nodeps openssl-0.9.8e.x86_64 openssl-devel-0.9.8e.x86_64
rpm -e --nodeps openssl-0.9.8e.i386 openssl-devel-0.9.8e.i386
卸载后再进行安装
rpm -ivh openssl-0.9.8zg-1.i386.rpm openssl-devel-0.9.8zg-1.i386.rpm[/code]
安装后会发现像yum等都不能正常使用,解决办法是添加旧的链接库链接,在制作openssl.spec文件的时候,我已经增加了下列软链接,下面这个步骤供用原始spec文件编译出的rpm安装包使用,使之支持已安装的其他软件的依赖:

点击(此处)折叠或打开

  1. cd /usr/lib
  2. ln -s libcrypto.so.0.9.8 libcrypto.so.6
  3. ln -s libssl.so.0.9.8 libssl.so.6
而后再按照上面的步骤编译生成openssh的rpm包,并安装,在只升级了openssl后还没有升级openssh前,测试ssh -V可能不会发现什么问题,但是用ssh 192.168.1.8登录到别的机器时,会报“ssh: symbol lookup error: ssh: undefined symbol: FIPS_mode”这个错误,这时的解决办法就是继续升级安装新版的openssh,没有升级openssh前,一定不要重启ssh服务,否则可能导致服务器ssh服务无法正常启动,不能远程ssh,只能在本机接上显示器处理,升级openssh后就不会出现报错了。

点击(此处)折叠或打开

  1. rpm -Uvh openssh-6.9p1-1.i386.rpm openssh-server-6.9p1-1.i386.rpm openssh-clients-6.9p1-1.i386.rpm openssh-askpass-6.9p1-1.i386.rpm

b) 升级openssh版本

用方法一中下载的源码包来自己编译生成RPM包。这个方法相对比较麻烦,因为有不少和X依赖的库需要安装。
安装依赖包,我的系统上就只差这些。如果你的编译时报错,请根据具体报错装上其它依赖包。

点击(此处)折叠或打开

  1. yum -y install libX11-devel libXt-devel gtk2-devel
  2. wget
  3. wget [/code]
  4. x11-ssh-askpass is a lightweight passphrase dialog for OpenSSH or other open variants of SSH. In particular, x11-ssh-askpass is useful with the Unix port of OpenSSH by Damien Miller and others, and Damien includes it in his RPM packages of OpenSSH.
  5. x11-ssh-askpass uses only the stock X11 libraries (libX11, libXt) for its user interface. This reduces its dependencies on external libraries (such as GNOME or Perl/Tk).
  6. [code]tar xvf openssh-6.9p1.tar.gz
  7. cp openssh-6.9p1/contrib/redhat/openssh.spec /usr/src/redhat/SPECS/
  8. cp openssh-6.9p1.tar.gz /usr/src/redhat/SOURCES/
  9. cp x11-ssh-askpass-1.2.4.1.tar.gz /usr/src/redhat/SOURCES/
  10. ####如果不生成askpass包的话,也可以按照下面两个步骤将其中两行涉及到askpass的内容设置为1后再编译,1的含义代表disable,如前面已执行过yum -y install libX11-devel libXt-devel gtk2-devel安装则可忽略此步骤######
  11. cd /usr/src/redhat/SPECS
  12. perl -i.bak -pe 's/^(%define no_(gnome|x11)_askpass)\s+0$/$1 1/' openssh.spec
  13. ##########################################################################################################
  14. rpmbuild -bb /usr/src/redhat/SPECS/openssh.spec
编译成功后生成的OpenSSH安装包

点击(此处)折叠或打开

  1. cd /usr/src/redhat/RPMS/`uname -i`
  2. ls -l
  3. openssh-6.9p1-1.i386.rpm
  4. openssh-askpass-6.9p1-1.i386.rpm
  5. openssh-askpass-gnome-6.9p1-1.i386.rpm
  6. openssh-clients-6.9p1-1.i386.rpm
  7. openssh-debuginfo-6.9p1-1.i386.rpm
  8. openssh-server-6.9p1-1.i386.rpm
安装RPM包,升级OpenSSH到6.9p1,实际环境中我只安装了以下几个包

点击(此处)折叠或打开

  1. rpm -Uvh openssh-6.9p1-1.i386.rpm openssh-server-6.9p1-1.i386.rpm openssh-clients-6.9p1-1.i386.rpm openssh-askpass-6.9p1-1.i386.rpm
验证SSH的新版本,并测试连接

点击(此处)折叠或打开

  1. ssh -v localhost
重启服务

点击(此处)折叠或打开

  1. service sshd restart

方法三:通过rpmfind.net等直接搜索下载编译好的rmp包。

安装的时候同样存在方法二中存在的openssl版本过低的问题,升级openssl版本后再继续一下步骤。
OpenSSL 1.0.2d 

点击(此处)折叠或打开

  1. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssl-1.0.2d-1.fc23.x86_64.rpm
  2. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssl-devel-1.0.2d-1.fc23.x86_64.rpm
  3. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssl-1.0.2d-1.fc23.i686.rpm
  4. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssl-devel-1.0.2d-1.fc23.i686.rpm
OpenSSH 6.9p1
点击(此处)折叠或打开
  1. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-6.9p1-1.fc23.x86_64.rpm
  2. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-server-6.9p1-1.fc23.x86_64.rpm
  3. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-clients-6.9p1-1.fc23.x86_64.rpm
  4. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-askpass-6.9p1-1.fc23.x86_64.rpm
  5. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-6.9p1-1.fc23.i686.rpm
  6. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-server-6.9p1-1.fc23.i686.rpm
  7. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-clients-6.9p1-1.fc23.i686.rpm
  8. wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-clients-6.9p1-1.fc23.i686.rpm
安装RPM包,升级OpenSSH到6.9p1

点击(此处)折叠或打开

  1. rpm -Uvh openssh*rpm
验证SSH的新版本
点击(此处)折叠或打开
  1. ssh -V
  2. OpenSSH_6.9p1, OpenSSL 1.0.2d 11 Jun 2015

阅读(13590) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~