Centos7升級OpenSSH版本至8.8p1


生產環境服務器安全掃描出OpenSSH漏洞問題,只能通過升級最新的OpenSSH版本解決。本文章適用於Centos7使用。
升級前先打開telnet或者vnc,否則升級失敗。可能無法連接服務器。升級完成后記得關閉telnet或者vnc

安裝相關依賴包

[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel pam* zlib*
  1. https://ftp.openssl.org/source/下載openssl,並上傳至服務器
    image.png

  2. 解壓openssl

[root@localhost ~]# tar zxvf openssl-1.1.1l.tar.gz
  1. 檢查環境
[root@localhost ~]# cd openssl-1.1.1l/
[root@localhost openssl-1.1.1l]# ./config --prefix=/usr/local/openssl

image.png

  1. 編譯並安裝
[root@localhost openssl-1.1.1l]# make && make install
  1. 替換當前系統的舊版本openssl(先保存原來的)
[root@localhost openssl-1.1.1l]# which openssl
/usr/bin/openssl
[root@localhost openssl-1.1.1l]# mv /usr/bin/openssl /usr/bin/openssl.old
[root@localhost openssl-1.1.1l]# mv /usr/lib64/openssl /usr/lib64/openssl.old
[root@localhost openssl-1.1.1l]# mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@localhost openssl-1.1.1l]# ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
[root@localhost openssl-1.1.1l]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1l]# ldconfig -v
  1. openssl安裝完成,查看版本
[root@localhost openssl-1.1.1l]# openssl version

image.png

  1. 查看openssh版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
  1. https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/下載openssh,並上傳至服務器

image.png

  1. 解壓
[root@localhost ~]# tar zxvf openssh-8.8p1.tar.gz 
  1. 移除舊版本
[root@localhost ~]# mv /etc/ssh /etc/ssh.old
  1. 編譯並安裝
[root@localhost ~]# cd openssh-8.8p1
[root@localhost openssh-8.8p1]# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening
[root@localhost openssh-8.8p1]# make && make install
  1. 修改啟動腳本
#拷貝啟動腳本
[root@localhost openssh-8.8p1]# cp ./contrib/redhat/sshd.init /etc/init.d/sshd
 
#修改啟動腳本
[root@localhost openssh-8.8p1]# vim /etc/init.d/sshd
 
#按如下圖修改,需要注意,此路徑是你安裝新版本的openssh路徑,根據你的實際情況修改
SSHD=/usr/local/openssh/sbin/sshd

image.png

  1. 修改sshd配置文件/etc/ssh/sshd_config
#直接用root登錄終端(此處根據自身情況考慮)
[root@localhost openssh-8.8p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
#設置是否允許X11轉發
[root@localhost openssh-8.8p1]# echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
#是否允許密碼驗證
[root@localhost openssh-8.8p1]# echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
  1. 卸載原有ssh(先安裝后卸載,也是怕升級失敗)
[root@localhost openssh-8.8p1]# for i in  $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done

出現提示告警

image.png

將警告中被修改的文件名字再改回來

[root@localhost ~]# mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config
[root@localhost ~]# mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
[root@localhost ~]# mv /etc/ssh/moduli.rpmsave /etc/ssh/moduli
  1. 安裝成功查看升級版本(如有報錯,請檢查環境變量)
[root@localhost ~]# ssh -V
  1. 查看sshd運行狀態
systemctl status sshd

image.png

  1. 設置開機啟動並啟動
[root@localhost ~]# systemctl enable sshd --now

注意!!!升級前記得打開telnet或者vnc,否則升級失敗會導致服務器SSH連接上不!!!

參考:
友人a筆記


免責聲明!

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



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