@
目錄
概述
由於安全漏洞掃描顯示OpenSSH版本過低需升級至最新版,故編寫該文檔。
本文轉載自link於2021-06-30由宇宙最帥的男人發布
查看服務器基本信息
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
實測中,我的Centos版本是7.2-1511,同樣成功
安裝升級依賴
[root@localhost ~]# yum -y install wget gcc zlib-devel openssl-devel pam-devel libselinux-devel
升級OPENSSL
備份舊版openssl
[root@localhost ~]# mv /usr/bin/openssl{,.bak}
[root@localhost ~]# mv /usr/include/openssl{,.bak}
解壓並編譯安裝
[root@localhost ~]# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
[root@localhost ~]# tar zxf openssl-1.1.1k.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/openssl-1.1.1k/
[root@localhost openssl-1.1.1k]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.1.1k]# make -j 2 && make install
配置調整
[root@localhost openssl-1.1.1k]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.1.1k]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@localhost openssl-1.1.1k]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1k]# ldconfig -v
驗證版本
[root@localhost openssl-1.1.1k]# openssl version
OpenSSL 1.1.1k 25 Mar 2021
升級OPENSSH
停止原有服務及備份數據
[root@localhost ~]# systemctl stop sshd
[root@localhost ~]# mv /etc/ssh{,.bak}
[root@localhost ~]# mv /etc/pam.d/sshd{,.bak}
卸載原有openssh包
[root@localhost ~]# rpm -e --nodeps `rpm -qa | grep openssh`
下載並解壓安裝包
[root@localhost ~]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
[root@localhost ~]# tar zxf openssh-8.6p1.tar.gz
[root@localhost ~]# cd openssh-8.6p1
編譯安裝
[root@localhost openssh-8.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --without-hardening
[root@localhost openssh-8.6p1]# make -j 2 && make install
拷貝配置文件並啟動
[root@localhost openssh-8.6p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.6p1]# mv /etc/pam.d/sshd.bak /etc/pam.d/sshd
[root@localhost openssh-8.6p1]# mv /etc/ssh /etc/ssh_update.bak
[root@localhost openssh-8.6p1]# mv /etc/ssh.bak /etc/ssh
[root@localhost openssh-8.6p1]# chmod 600 /etc/ssh/*key
[root@localhost openssh-8.6p1]# chkconfig --add sshd
[root@localhost openssh-8.6p1]# chkconfig sshd on
[root@localhost openssh-8.6p1]# systemctl restart sshd
允許Root登陸
[root@localhost ~]# sed -i 's/^#\(PermitRootLogin \).*/\1yes/' /etc/ssh/sshd_config
版本驗證
[root@localhost openssh-8.6p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1k 25 Mar 2021
-
我的驗證
-
ssh-V、sshd-V、openssl version、systemctl status sshd.service等各項驗證
-
第三方工具驗證 OK
-
SSH到別的服務器 OK
-
別的服務器SSH到測試機
-
報錯
-
原因:是因為ssh升級過后,服務器的公鑰信息改變了,所以導致無法連接的。
-
用OpenSSH的人都知ssh會把你每個你訪問過計算機的公鑰(public key)都記錄在~/.ssh/known_hosts。
-
當下次訪問相同計算機時,OpenSSH會核對公鑰。如果公鑰不同,OpenSSH會發出警告,如果我們重新安裝系統,其公鑰信息還在,連接會出現如上圖所示
-
解決方法:
rm -rf ~/.ssh/known_hosts 優點:干凈利索 / 缺點:把其他正確的公鑰信息也刪除,下次鏈接要全部重新經過認證
vi ~/.ssh/known_hosts 刪除對應ip的相關rsa信息優點:其他正確的公鑰信息保留 / 缺點:還要vi,還要找到對應信息,稍微優點繁瑣
ssh-keygen -R 172.16.5.251清除舊的公鑰信息優點:快、穩、狠 / 缺點:沒有缺點
遇到的問題
我升級過程沒有遇到此問題,測試機重啟過沒有遇到,一切正常
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
解決辦法
grep sshd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp