CentOS 5.X自带的OpenSSH版本很低,还是4.3P2的,不支持SFTP Chroot功能,而且一些漏洞扫描工具会根据版本号报出openssh漏洞,加上之前的心脏出血漏洞,也有升级OpenSSL的需求。
因此,特总结了以下三种升级到新版本的方法:
实际操作中如果提前将自动超时取消(执行 export TMOUT=0),并在未最终升级完openssh前不重启ssh服务,一般都不会断开远程ssh连接。为了升级安全,可先启用telnet服务,默认系统是没有启用这个服务的。
启用Telnet远程管理
点击(此处)折叠或打开
-
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
}
重启xinetd,开启Telnet服务,如果没有安装xinetd的话,需要先进行安装
点击(此处)折叠或打开
- yum install xinetd
- yum install telnet-server
点击(此处)折叠或打开
- service xinetd restart
点击(此处)折叠或打开
- netstat -tnlp | grep :23
方法一:源码包编译安装
点击(此处)折叠或打开
- wget
- tar xvf openssh-6.9p1.tar.gz
- cd openssh-6.9p1
- ./configure --prefix=/usr --sysconfdir=/etc/ssh
- make
- make install
建议安装还是换个路径比较好,特别是线上服务器。下面给出的是官方给出的几种方案,根据自己情况调整吧!
点击(此处)折叠或打开
- To install OpenSSH with default options:
- ./configure
- make
- make install
- This will install the OpenSSH binaries in /usr/local/bin, configuration files
- in /usr/local/etc, the server in /usr/local/sbin, etc. To specify a different
- installation prefix, use the --prefix option to configure:
- ./configure --prefix=/opt
- make
- make install
- Thsi will install OpenSSH in /opt/{bin,etc,lib,sbin}. You can also override
- specific paths, for example:
- ./configure --prefix=/opt --sysconfdir=/etc/ssh
- make
- make install
- This will install the binaries in /opt/{bin,lib,sbin}, but will place the
- 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版本,升级过程记录如下:
点击(此处)折叠或打开
- wget
- cp openssl-0.9.8zg.tar.gz /usr/src/redhat/SOURCES/
- tar xvf openssl-0.9.8zg.tar.gz
- cp openssl-0.9.8zg/openssl.spec /usr/src/redhat/SPECS/
- rpmbuild /usr/src/redhat/SPECS/openssl.spec
- cd /usr/src/redhat/RPMS/i386/
- ls -l
- -rw-r--r-- 1 root root 1219140 06-24 11:22 openssl-0.9.8zg-1.i386.rpm
- -rw-r--r-- 1 root root 118129 06-24 11:22 openssl-debuginfo-0.9.8zg-1.i386.rpm
- -rw-r--r-- 1 root root 2187227 06-24 11:22 openssl-devel-0.9.8zg-1.i386.rpm
- -rw-r--r-- 1 root root 608743 06-24 11:22 openssl-doc-0.9.8zg-1.i386.rpm
在openssl.spec原文件的基础上对应增加以下对操作版本判断的语句,
点击(此处)折叠或打开
- %ifarch i386 i486 i586 i686
- %attr(0755,root,root) /usr/lib/*.so*
- %attr(0755,root,root) /usr/lib/engines/*.so*
- %endif
- %ifarch x86_64
- %attr(0755,root,root) /usr/lib64/*.so*
- %attr(0755,root,root) /usr/lib64/engines/*.so*
- %endif
- ................
- %ifarch i386 i486 i586 i686
- %attr(0644,root,root) /usr/lib/*.a
- %attr(0644,root,root) /usr/lib/pkgconfig/
- %endif
- %ifarch x86_64
- %attr(0644,root,root) /usr/lib64/*.a
- %attr(0644,root,root) /usr/lib64/pkgconfig/
- %endif
openssl.spec安装新版openssl
点击(此处)折叠或打开
- 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参数强制安装:
点击(此处)折叠或打开
- rpm --nodeps -Uvh openssl-0.9.8zg-1.i386.rpm openssl-devel-0.9.8zg-1.i386.rpm
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安装包使用,使之支持已安装的其他软件的依赖:
点击(此处)折叠或打开
- cd /usr/lib
- ln -s libcrypto.so.0.9.8 libcrypto.so.6
- ln -s libssl.so.0.9.8 libssl.so.6
点击(此处)折叠或打开
- 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依赖的库需要安装。安装依赖包,我的系统上就只差这些。如果你的编译时报错,请根据具体报错装上其它依赖包。
点击(此处)折叠或打开
- yum -y install libX11-devel libXt-devel gtk2-devel
- wget
- wget [/code]
- 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.
- 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).
- [code]tar xvf openssh-6.9p1.tar.gz
- cp openssh-6.9p1/contrib/redhat/openssh.spec /usr/src/redhat/SPECS/
- cp openssh-6.9p1.tar.gz /usr/src/redhat/SOURCES/
- cp x11-ssh-askpass-1.2.4.1.tar.gz /usr/src/redhat/SOURCES/
- ####如果不生成askpass包的话,也可以按照下面两个步骤将其中两行涉及到askpass的内容设置为1后再编译,1的含义代表disable,如前面已执行过yum -y install libX11-devel libXt-devel gtk2-devel安装则可忽略此步骤######
- cd /usr/src/redhat/SPECS
- perl -i.bak -pe 's/^(%define no_(gnome|x11)_askpass)\s+0$/$1 1/' openssh.spec
- ##########################################################################################################
- rpmbuild -bb /usr/src/redhat/SPECS/openssh.spec
点击(此处)折叠或打开
- cd /usr/src/redhat/RPMS/`uname -i`
- ls -l
- openssh-6.9p1-1.i386.rpm
- openssh-askpass-6.9p1-1.i386.rpm
- openssh-askpass-gnome-6.9p1-1.i386.rpm
- openssh-clients-6.9p1-1.i386.rpm
- openssh-debuginfo-6.9p1-1.i386.rpm
- openssh-server-6.9p1-1.i386.rpm
点击(此处)折叠或打开
- 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 -v localhost
点击(此处)折叠或打开
- service sshd restart
方法三:通过rpmfind.net等直接搜索下载编译好的rmp包。
安装的时候同样存在方法二中存在的openssl版本过低的问题,升级openssl版本后再继续一下步骤。OpenSSL 1.0.2d
点击(此处)折叠或打开
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssl-1.0.2d-1.fc23.x86_64.rpm
- 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
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssl-1.0.2d-1.fc23.i686.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssl-devel-1.0.2d-1.fc23.i686.rpm
点击(此处)折叠或打开
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-6.9p1-1.fc23.x86_64.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-server-6.9p1-1.fc23.x86_64.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-clients-6.9p1-1.fc23.x86_64.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/o/openssh-askpass-6.9p1-1.fc23.x86_64.rpm
-
wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-6.9p1-1.fc23.i686.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-server-6.9p1-1.fc23.i686.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-clients-6.9p1-1.fc23.i686.rpm
- wget ftp://fr2.rpmfind.net/linux/fedora/linux/development/rawhide/i386/os/Packages/o/openssh-clients-6.9p1-1.fc23.i686.rpm
点击(此处)折叠或打开
- rpm -Uvh openssh*rpm
点击(此处)折叠或打开
- ssh -V
-
OpenSSH_6.9p1, OpenSSL 1.0.2d 11 Jun 2015