Centos6.5升級openssh至7.4版本


一,備份配置文件,以備升級失敗進行回退

 

二,下載安裝包

wget http://www.zlib.net/zlib-1.2.11.tar.gz

wget https://openbsd.mirror.netelligent.ca/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz

 

三,查看當前系統版本

 

 技術分享圖片

 

 

四,開啟telnet連接通道

yum安裝telnet

yum -y install telnet-server*

關閉防火牆

/etc/init.d/iptables stop

編輯配置文件

 vim /etc/xinetd.d/telnet

disable值yes改為no

允許root用戶通過telnet登錄

mv /etc/securetty /etc/securetty.old

啟動並設置開機啟動

/etc/init.d/xinetd start

                         

chkconfig xinetd on

驗證 telnet 127.0.0.1

 

五,安裝編譯工具包

 yum  install gcc pam-devel zlib-devel -y

 

六,安裝zlib

解壓

tar -xf zlib-1.2.11.tar.gz

進入目錄

cd zlib-1.2.11

編譯

./configure --prefix=/usr

make

卸載

rpm -e --nodeps zlib

make install

共享庫文件注冊到系統

echo ‘/usr/lib‘ >> /etc/ld.so.conf

ldconfig

 

七,升級openssl

備份當前openssl

mv /usr/lib64/openssl/ /usr/lib64/openssl.old

 

mv /usr/bin/openssl /usr/bin/openssl.old

mv /etc/pki/ca-trust/extracted/openssl /etc/pki/ca-trust/extracted/openssl.old

如下兩個庫文件必須先備份,因系統內部分工具(如yum、wget等)依賴此庫,而新版OpenSSL不包含這兩個庫

cp /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.10.old

cp /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.10.old

卸載當前openssl

rpm -qa |grep openssl|xargs -i rpm -e --nodeps {}

安裝openssl

tar -xf openssl-1.0.2m.tar.gz

cd openssl-1.0.2m

./config --prefix=/usr/local/ssl --openssldir=/etc/ssl --shared zlib

echo $?

make

make test

make install

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

ln -s /usr/local/ssl/include/openssl /usr/include/openssl

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf

ldconfig -v

驗證

openssl version

 技術分享圖片

 

 

PS:必須加上--shared,否則編譯時會因找不到新安裝的openssl的類庫而報錯

 

恢復共享庫

mv  /usr/lib64/libcrypto.so.10.old  /usr/lib64/libcrypto.so.10

mv  /usr/lib64/libssl.so.10.old  /usr/lib64/libssl.so.10

 

 

八,升級openssh

備份當前openssh

mv /etc/ssh /etc/ssh.old

卸載

rpm -qa |grep openssh|xargs -i rpm -e --nodeps {}

openssh安裝前環境配置

install  -v -m700 -d /var/lib/sshd

chown  -v root:sys /var/lib/sshd

groupadd -g 51 sshd

useradd  -c ‘sshd PrivSep‘ -d /var/lib/sshd -g sshd -s /bin/false -u 51 sshd

 

源碼安裝

tar -xf openssh-7.4p1.tar.gz

cd openssh-7.4p1

./configure --prefix=/usr  --sysconfdir=/etc/ssh  --with-md5-passwords  --with-pam  --with-zlib --with-ssl-dir=/usr/local/ssl --with-privsep-path=/var/lib/sshd

make && make install

安裝后環境配置

install -v -m755    contrib/ssh-copy-id /usr/bi

install -v -m644    contrib/ssh-copy-id.1 /usr/share/man/man1

install -v -m755 -d /usr/share/doc/openssh-7.4p1

install -v -m644    INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.4p1

 

驗證是否安裝成功

 

 技術分享圖片

 

啟動openssh服務

echo ‘X11Forwarding yes‘ >> /etc/ssh/sshd_config

允許root直接登錄

echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

拷貝啟動文件設置chkconfig

cp -p contrib/redhat/sshd.init /etc/init.d/sshd

chmod +x /etc/init.d/sshd

chkconfig  --add  sshd

chkconfig  sshd  on

 

重啟sshd需要通過telnet才能登錄啟動sshd了

/etc/init.d/sshd restart

 

如果需要還原原來的ssh配置(如不需要則不進行一下操作)

rm -rf /etc/ssh

mv /etc/ssh.old /etc/ssh

 

驗證 openssh已經升級為更加安全的高版本

 技術分享圖片

 


免責聲明!

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



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