當前版本信息:
OS: RHEL5.8 X64
OpenSSH: 4.3p2
openssl: 0.9.8e
zlib: 1.2.3-4
OpenSSH版本7.4p1依賴的OpenSSL版本爲1.0.2k,而不是其最新版1.1.0e(使用此版會升級失敗)。ZLIB可以使用最新版1.2.11,redhat5.8自帶的zlib版本爲1.2.3,無須進行升級。
三者下載地址:
http://www.zlib.net/
http://www.openssl.org/
http://www.openssh.org/
安裝telnet
因升級OpenSSH過程中需要卸載現有OpenSSH, 因此爲了保持服務器的遠程連接可用,需要啓用telnet服務作爲替代,如升級出現問題,也可通過telnet登錄服務器進行回退
[root@localhost ~]# rpm -ivh telnet-server-0.17-39.el5.x86_64.rpm
[root@localhost ~]# vi /etc/xinetd.d/telnet //將其中disable字段的yes改爲no以啓用telnet服務
[root@localhost ~]# mv /etc/securetty /etc/securetty.old
[root@localhost ~]# service xinetd restart
[root@localhost ~]# chkconfig xinetd on
升級OpenSSL
1、備份當前openssl:
[root@localhost openssl]# find / -name openssl
/root/percona-xtrabackup-2.4.8/extra/yassl/include/openssl
/usr/share/doc/ruby-1.8.5/sample/openssl
/usr/lib64/openssl
/usr/include/openssl
/usr/lib/openssl
/usr/lib/ruby/1.8/openssl
/usr/bin/openssl
[root@localhost ~]# mv /usr/include/openssl /usr/include/openssl.old
[root@localhost ~]# mv /usr/bin/openssl /usr/bin/openssl.old
[root@localhost ~]# mv /usr/lib/openssl /usr/lib/openssl.old
[root@localhost ~]# mv /usr/lib64/openssl /usr/lib64/openssl.old
--如下兩個庫文件必須先備份,因系統內部分工具(如yum、wget等)依賴此庫,而新版OpenSSL不包含這兩個庫(RHEL6.4需要備份的爲libcrypto.so.10、libcrypto.so.6及libssl.so.10、libssl.so.6)
[root@localhost ~]# cp /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.old
[root@localhost ~]# cp /usr/lib64/libssl.so /usr/lib64/libssl.so.old
2、卸載當前openssl:
[root@localhost ~]# rpm -aq|grep openssl
openssl-devel-0.9.8e-22.el5
openssl-0.9.8e-22.el5
openssl-devel-0.9.8e-22.el5
openssl-0.9.8e-22.el5
[root@localhost ~]# rpm -e openssl-0.9.8e-22.el5 --allmatches --nodeps
[root@localhost ~]# rpm -e openssl-devel-0.9.8e-22.el5 --allmatches --nodeps
3、解壓openssl_1.0.2k源碼並編譯安裝:
[root@localhost ~]# tar -zvxf openssl-1.0.2k.tar.gz
[root@localhost ~]# cd openssl-1.0.2k
[root@localhost openssl-1.0.2k]# ./config --prefix=/usr --openssldir=/etc/ssl --shared zlib
[root@localhost openssl-1.0.2k]# make
[root@localhost openssl-1.0.2k]# make test //必須執行這一步結果爲pass才能繼續,否則即使安裝完成,ssh也無法使用
[root@localhost openssl-1.0.2k]# make install
[root@localhost openssl-1.0.2k]# openssl version -a //查看升級是否成功
--測試發現,RHEL5.X安裝過程中會自動建立libssl.so.6、libcrypto.so.6的軟連接分別指向前面備份的libssl.so.old、libcrypto.so.old;RHEL6.4下爲libssl.so.10、libcrypto.so.10指向libssl.so.10.old、libcrypto.so.10.old,以及libssl.so.6、libcrypto.so.6指向libssl.so.6.old、libcrypto.so.6.old,也會自動建立,故無需額外執行恢復操作,以上文件均在/usr/lib64/下。如果RHEL5.X下安裝完成後libssl.so.6及libcrypto.so.6不存在(RHEL6.4下爲libssl.so.6、libcrypto.so.6、libssl.so.10及libcrypto.so.10),用之前庫文件的備份進行恢復,或者手動建軟連接,否則某些服務找不到這兩項將無法啓動
升級OpenSSH
1、備份當前openssh:
[root@localhost ~]# mv /etc/ssh /etc/ssh.old
2、卸載當前openssh:
[root@localhost ~]# rpm -aq|grep openssh
openssh-4.3p2-82.el5
openssh-clients-4.3p2-82.el5
openssh-server-4.3p2-82.el5
openssh-askpass-4.3p2-82.el5
[root@localhost ~]# rpm -e openssh-4.3p2-82.el5 --nodeps
[root@localhost ~]# rpm -e openssh-clients-4.3p2-82.el5 --nodeps
[root@localhost ~]# rpm -e openssh-server-4.3p2-82.el5 --nodeps
[root@localhost ~]# rpm -e openssh-askpass-4.3p2-82.el5 --nodeps
3、openssh安裝前環境配置:
[root@localhost ~]# install -v -m700 -d /var/lib/sshd
[root@localhost ~]# chown -v root:sys /var/lib/sshd
[root@localhost ~]# groupadd -g 50 sshd
[root@localhost ~]# useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd
4、解壓openssh_7.4p1源碼並編譯安裝:
[root@localhost ~]# tar -zvxf openssh-7.4p1.tar.gz
[root@localhost ~]# cd openssh-7.4p1
[root@localhost openssh-7.4p1]# ./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.4p1]# make && make install
5、openssh安裝後環境配置:
在openssh編譯目錄執行如下命令
[root@localhost openssh-7.4p1]# install -v -m755 contrib/ssh-copy-id /usr/bin
[root@localhost openssh-7.4p1]# install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
[root@localhost openssh-7.4p1]# install -v -m755 -d /usr/share/doc/openssh-7.4p1
[root@localhost openssh-7.4p1]# install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.4p1
[root@localhost openssh-7.4p1]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k 26 Jan 2017
6、啓用OpenSSH服務:
在openssh編譯目錄執行如下命令(並對/etc/ssh/sshd_config文件根據系統需求進行相應的修改)
[root@localhost openssh-7.4p1]# echo "X11Forwarding yes" >> /etc/ssh/sshd_config
[root@localhost openssh-7.4p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
[root@localhost openssh-7.4p1]# cp -p contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-7.4p1]# chmod +x /etc/init.d/sshd
[root@localhost openssh-7.4p1]# chkconfig --add sshd
[root@localhost openssh-7.4p1]# chkconfig sshd on
[root@localhost openssh-7.4p1]# chkconfig --list sshd
[root@localhost openssh-7.4p1]# service sshd restart
以ssh登錄系統,確認一切都正常後,關閉telnet服務以保證系統安全性
[root@localhost ~]# mv /etc/securetty.old /etc/securetty
[root@localhost ~]# chkconfig xinetd off
[root@localhost ~]# service xinetd stop