1. 程式人生 > 其它 >ssh升級8.6

ssh升級8.6

CVE-2021-28041漏洞描述:

OpenSSH(OpenBSD Secure Shell)是Openbsd計劃組的一套用於安全訪問遠端計算機的連線工具。該工具是SSH協議的開源實現,支援對所有的傳輸進行加密,可有效阻止竊聽、連線劫持以及其他網路級的攻擊。 OpenSSH before 8.5 存在安全漏洞,攻擊者可利用該漏洞在遺留作業系統上不受約束的代理套接字訪問。

解決辦法:

升級OpenSSH至最新版本(8.6p1)

注意:升級OpenSSH前,需要先升級OpenSSL版本。升級方法見:https://blog.csdn.net/lhrm0213/article/details/117561734

準備工作,安裝telnet,避免升級失敗後無法ssh登入.

yum -y install telnet-server.x86_64  //telnet伺服器
yum list | grep telnet-server  //telnet客戶端(可不安裝)
yum list | grep xinetd //xinetd守護程序

#配置開機啟動
systemctl enable xinetd.service
systemctl enable telnet.socket

#啟動服務
systemctl start telnet.socket
systemctl start xinetd

#檢視埠,看到23埠已開啟
netstat -ntlp

#開啟防火牆允許訪問23埠(沒開防火牆跳過此步驟)
firewall-cmd --add-port=23/tcp --permanent
firewall-cmd --reload

#預設root無法遠端訪問,修改/etc/securetty
vi /etc/securetty
在末尾新增
pts/0
pts/1

測試使用telnet登入伺服器

  

1. 下載OpenSSH

下載地址: https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

#進入要下載的目錄
[root@localhost ~]# cd /usr/local/src/

#下載原始碼
[root@localhost src]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

#解壓
[root@localhost src]# tar -zxvf openssh-8.6p1.tar.gz 

  

2. 編譯安裝

#進入目錄
[root@172-15-4-5 src]# cd openssh-8.6p1

#編譯
[root@172-15-4-5 openssh-8.6p1]#  ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/lib64 --without-hardening
#檢視結果,輸出為0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0

[root@172-15-4-5 openssh-8.6p1]# make

#檢視結果,輸出為0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0

[root@172-15-4-5 openssh-8.6p1]# make install

#檢視結果,輸出為0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0

  

3. 配置SSH檔案驗證

#允許root賬戶登入
[root@localhost openssh-8.6p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# grep "^PermitRootLogin"  /etc/ssh/sshd_config      
PermitRootLogin yes

[root@localhost openssh-8.6p1]# echo "UseDNS no" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# grep  "UseDNS"  /etc/ssh/sshd_config    
UseDNS no

#複製檔案到系統服務目錄
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

#新增執行許可權
[root@localhost openssh-8.6p1]# chmod +x /etc/init.d/sshd

#新增服務,配置開機啟動
[root@localhost openssh-8.6p1]# chkconfig --add sshd
[root@localhost openssh-8.6p1]# systemctl enable sshd
[root@localhost openssh-8.6p1]# chkconfig sshd on

#原來的服務移走,否走有時重啟後ssh服務起不來
[root@localhost openssh-8.6p1]# mv /usr/lib/systemd/system/sshd.service  /home/

[root@localhost openssh-8.4p1]# /etc/init.d/sshd restart
Restarting sshd (via systemctl):                           [  OK  ]

#檢視埠
[root@localhost openssh-8.4p1]# netstat -ntlp
#22埠正常即可

#可以通過systemctl start/stop/restart 啟動/停止/重啟sshd服務
#檢視版本
[root@localhost openssh-8.4p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1h  22 Sep 2020

  

5. 關閉telnet

[root@172-15-4-5 src]# systemctl disable xinetd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service.
[root@172-15-4-5 src]# systemctl stop xinetd.service
[root@172-15-4-5 src]# systemctl disable telnet.socket
Removed symlink /etc/systemd/system/sockets.target.wants/telnet.socket.
[root@172-15-4-5 src]# systemctl stop telnet.socket

  轉載:https://blog.csdn.net/lhrm0213/article/details/117565350

ml