升級OpenSSH版本(8.8版本)


1.前言

Hello大家好我是哈皮,最近項目中被報告低版本SSH存在漏洞,需要進行升級(升級到目前最新的8.8版本),記錄一下升級過程。

2.資源

https://github.com/openssh/openssh-portable/tags
https://github.com/openssl/openssl/tags
# 我的版本
https://github.com/happyjava007/share/raw/main/openssh-8.8p1.tar.gz
https://github.com/happyjava007/share/raw/main/openssl-3.0.1.tar.gz

3.開啟Telnet登陸

為了避免升級失敗,導致無法登陸服務器,所以需要開啟Telnet登陸。

systemctl start telnet.socket
telnet 127.0.0.1 # 測試是否可以正常登陸

4.升級OpenSSL

# 備份
mv /usr/bin/openssl /usr/bin/openssl_old

# 進入OpenSSL源碼目錄
./config shared && make && make install

# 檢查安裝
openssl version
# 報錯
# openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
# 在OpenSSL源碼目錄
cp libssl.so.3 /usr/lib64/
cp libcrypto.so.3 /usr/lib64/

5.升級OpenSSH

# 備份
mkdir /etc/ssh_old
mv /etc/ssh/* /etc/ssh_old/

# 進入openssh目錄
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/lib64/ --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux

# 警告
PAM is enabled. You may need to install a PAM control file 
for sshd, otherwise password authentication may fail. 
Example PAM control files can be found in the contrib/ 
subdirectory

ls contrib # 里面有各種系統

# 備份
mv /etc/pam.d/sshd /etc/pam.d/sshd_bak
# 復制
cp contrib/redhat/sshd.pam /etc/pam.d/sshd # 根據系統選擇

# 安裝
make && make install

# 根據提示執行
/usr/sbin/sshd -t -f /etc/ssh/sshd_config

vim /etc/ssh/sshd_config
PermitRootLogin yes # 開啟root登陸

# 移除舊版本的文件
mv /usr/lib/systemd/system/sshd.service /etc/ssh_old/
mv /usr/lib/systemd/system/sshd.socket /etc/ssh_old/

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

systemctl daemon-reload
systemctl restart sshd

升級完后,ssh登陸可能報錯

Host key verification failed.

執行以下命令即可

ssh-keygen -R <server_ip>


免責聲明!

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



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