天天看點

Centos 6.5更新openssh到7.9p1

前言:

近期因centos 6.x 預設openssh掃描存在大量漏洞,基于安全考慮,需要将openssh_5.3p1更新為最新版,網上查了很多教程,發現openssh存在大量依賴,不解決依賴問題很難保證其他服務。而openssl又被大量程式依賴。實在是頭疼。最後發現一個不破壞各種依賴又可以完美更新的方案。

以下作業系統是centos6.5

開啟telnet
##安裝telnet
yum -y install telnet-server*
service iptables stop
chkconfig iptables off
sed -i 's/\(.*\)disable\(.*\)/\ \ \ \ \ \ \ \ disable\ \ \ \ \ \ \ \ \ =\ no/g'   /etc/xinetd.d/telnet  ##将其中disable字段的yes改為no以啟用telnet服務  
mv /etc/securetty /etc/securetty.old   #允許root使用者通過telnet登入
service xinetd start
chkconfig xinetd on
           
檢查環境

官方給出的文檔中提到的先決條件openssh安裝依賴zlib1.1.4并且openssl>=1.0.1版本就可以了。那麼直接看目前系統的openssl版本是多少

[[email protected] ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[[email protected] ~]# rpm -q zlib
zlib-1.2.3-29.el6.x86_64
[[email protected] ~]# rpm -q zlib-devel
zlib-devel-1.2.3-29.el6.x86_64
           

發現自帶的openssl版本符合openssh7.9p1的安裝條件,自帶的zlib也符合OpenSSH7.9P1的依賴。那麼就直接安裝吧

安裝相關元件并更新openssh
yum install -y gcc openssl-devel pam-devel rpm-build pam-devel 
#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
rpm -e `rpm -qa | grep openssh` --nodeps
cd /usr/local/src/ && tar zxvf openssh-7.9p1_Compile.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
           
關閉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檢視版本号.
           

繼續閱讀