Linux升級OpenSSH修復高危漏洞

前言:
近期因centos 6.x和Redhat 6.x 默認openssh掃描存在大量漏洞,基於安全考慮,需要將openssh_5.3p1升級爲最新版,網上查了很多教程,發現openssh存在大量依賴,不解決依賴問題很難保證其他服務。而openssl又被大量程序依賴。實在是頭疼。最後發現一個不破壞各種依賴又可以完美升級的方案。


1. 開啓telnet避免無法登陸

1.1 安裝telnet服務
yum -y install telnet-server*
1.2  啓用telnet
先關閉防火牆,阿里雲把23端口加入安全組,否則telnet可能無法連接
service iptables stop
chkconfig iptables off
vi /etc/xinetd.d/telnet
將其中disable字段的yes改爲no以啓用telnet服務
mv /etc/securetty /etc/securetty.old    #允許root用戶通過telnet登錄
service xinetd start                    #啓動telnet服務
chkconfig xinetd on                     #使telnet服務開機啓動,避免升級過程中服務器意外重啓後無法遠程登錄系統
telnet [ip]                             #新開啓一個遠程終端以telnet登錄驗證是否成功啓用
2. 檢查環境
官方給出的文檔中提到的先決條件openssh安裝依賴zlib1.1.4並且openssl>=1.0.1版本就可以了。那麼直接看當前系統的openssl版本是多少,發現自帶的openssl版本符合openssh7.9p1的安裝條件,自帶的zlib也符合OpenSSH7.9P1的依賴。那麼就直接安裝吧

[root@zabbix-serv ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@zabbix-serv ~]# rpm -q zlib
zlib-1.2.3-29.el6.x86_64
[root@zabbix-serv ~]# rpm -q zlib-devel
zlib-devel-1.2.3-29.el6.x86_64
3. 安裝相關組件並升級openssh
yum install -y gcc openssl-devel pam-devel rpm-build pam-devel 
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
rpm -e `rpm -qa | grep openssh` --nodeps
tar -zxvf openssh-7.9p1.tar.gz
cd openssh-7.9p1/
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers && make && make install
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin\ yes/g' /etc/ssh/sshd_config #或手動修改PermitRootLogin no 修改爲 PermitRootLogin yes 允許root遠程登陸
sed -i 's/#PermitEmptyPasswords\(.*\)/PermitEmptyPasswords\ no/g' /etc/ssh/sshd_config  ##禁止空密碼
sed -i 's/^SELINUX\(.*\)/SELINUX=disabled/g' /etc/selinux/config  ##重點來了~~~禁止selinux 否則重啓後會登錄失敗
echo 'KexAlgorithms [email protected],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支持的算法
cp contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
service sshd start
service sshd restart
chkconfig --list sshd
ssh -V
4. 關閉telnet開啓防火牆
mv /etc/securetty.old /etc/securetty   #允許root用戶通過telnet登錄
service xinetd stop
chkconfig xinetd off
service iptables start
chkconfig iptables on
將之前改過的disable=yes又改回去成no.
隨後再將修改iptables將23端口關閉,並重啓iptables服務.
至此,可以再開ssh登錄,用ssh -V查看版本號.
 
如有必要,可重新開啓防火牆
service iptables start
chkconfig iptables on
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章