centos6.5升級openssh至7.9p1


環境說明
系統環境:centos 6.5 x64 openssh-5.3p1
升級原因:低版本openssh存在漏洞
升級目標:openssh-7.9p1

檢查環境
官方文檔中提到的先決條件openssh安裝依賴zlib1.1.4並且openssl>=1.0.1版本就可以了。

當前版本正好符合openssh7.9p1的安裝條件,而且zlib也符合OpenSSH7.9P1的依賴,可以進行直接安裝:
[root@noway11 ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@noway11 ~]# rpm -q zlib
zlib-1.2.3-29.el6.x86_64
[root@noway11 ~]# rpm -q zlib-devel
zlib-devel-1.2.3-29.el6.x86_64

開啟telnet-server服務
為防止openssh升級過程中斷開連接,最好開啟telnet-server服務以防萬一
[root@noway11 ~]yum -y install telnet-server*
[root@noway11 ~]service iptables stop
[root@noway11 ~]chkconfig iptables off
[root@noway11 ~]sed -i 's/\(.*\)disable\(.*\)/\ \ \ \ \ \ \ \ disable\ \ \ \ \ \ \ \ \ =\ no/g' /etc/xinetd.d/telnet ##將其中disable字段的yes改為no以啟用telnet服務
[root@noway11 ~]mv /etc/securetty /etc/securetty.old #允許root用戶通過telnet登錄
[root@noway11 ~]service xinetd start
[root@noway11 ~]chkconfig xinetd on

openssh-7.9p1升級
[root@noway11 ~]yum install -y gcc openssl-devel pam-devel rpm-build pam-devel
[root@noway11 ~]#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz #或者從官網下載,上傳至服務器
[root@noway11 ~]rpm -e `rpm -qa | grep openssh` --nodeps
[root@noway11 ~]cd /usr/local/src/ && tar zxvf openssh-7.9p1_Compile.tar.gz && cd openssh-7.9p1
[root@noway11 ~]./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers && make && make install
[root@noway11 ~]sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin\ yes/g' /etc/ssh/sshd_config #或手動修改PermitRootLogin no 修改為 PermitRootLogin yes 允許root遠程登陸
[root@noway11 ~]sed -i 's/#PermitEmptyPasswords\(.*\)/PermitEmptyPasswords\ no/g' /etc/ssh/sshd_config ##禁止空密碼
[root@noway11 ~]sed -i 's/^SELINUX\(.*\)/SELINUX=disabled/g' /etc/selinux/config ##重點來了~~~禁止selinux 否則重啟后會登錄失敗
[root@noway11 ~]echo 'KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1' >> /etc/ssh/sshd_config ## 寫上新版ssh支持的算法
[root@noway11 ~]cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@noway11 ~]chkconfig --add sshd
[root@noway11 ~]chkconfig sshd on
[root@noway11 ~]service sshd start
[root@noway11 ~]service sshd restart
[root@noway11 ~]chkconfig --list sshd
[root@noway11 ~]ssh -V

關閉telnet-server服務
升級完成,通過ssh可以遠程到服務器后,可以關閉telnet-server服務
[root@noway11 ~]mv /etc/securetty.old /etc/securetty #允許root用戶通過telnet登錄
[root@noway11 ~]service xinetd stop
[root@noway11 ~]chkconfig xinetd off
[root@noway11 ~]service iptables start
[root@noway11 ~]chkconfig iptables on
將之前改過的disable=yes又改回去成no.
隨后再將修改iptables將23端口關閉,並重啟iptables服務.
至此,可以再開ssh登錄,用ssh -V查看版本號

啟動報錯問題

sshd啟動報錯:Bad SSH2 KexAlgorithms '...'

查詢支持的算法:
[user@localhost ~]# ssh -Q kex
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1
diffie-hellman-group14-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group-exchange-sha1
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
curve25519-sha256
curve25519-sha256@libssh.org
也可以用paste -s -d,直接將查詢結果串接並寫入配置文件:

echo 'KexAlgorithms' `ssh -Q kex | paste -d, -s` >> /etc/ssh/sshd_config

報錯排查技巧
遇到錯誤,服務端日志必須是首選檢查點。
可借助sshd -d啟用debug模式來排查問題。
可以用ssh -vvv以便更快找到問題。

更多報錯處理方法可以參考:https://segmentfault.com/a/1190000018629266


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM