漏洞掃描工具掃描出openssh用戶枚舉漏洞,搜索資料得知無補丁和升級包,解決這個漏洞得安裝漏洞修復以後的版本version>7.8。node
linux版本: CentOS Linux release 7.5.1804linux
ssh版本: OpenSSH_7.4p1vim
備份服務器
備份ssh配置網絡
mkdir -p /bakssh
cp -ar /etc/ssh /baksocket
備份老版本的openssh軟件包工具
[root@localhost soft]# rpm -qa|grep openssh
openssh-7.4p1-16.el7.x86_64
openssh-server-7.4p1-16.el7.x86_64
openssh-clients-7.4p1-16.el7.x86_64測試
能夠去網上下載,這裏上傳的雲盤:ui
連接: https://pan.baidu.com/s/1K9PRWji99IeSoWc6O6rcfw 提取碼: ex5v
下載openssh7.4.zip, 將這些文件所有上傳至要升級的服務器。
安裝telnet服務,防止ssh升級後登陸不上
網盤裏telnet.zip解壓安裝便可:
[root@localhost telnet_dir]# ls telnet-0.17-64.el7.x86_64.rpm telnet-server-0.17-64.el7.x86_64.rpm xinetd-2.3.15-13.el7.x86_64.rpm [root@localhost telnet_dir]# rpm -iv --force --nodeps *.rpm [root@localhost telnet_dir]# chkconfig xinetd on 注意:正在將請求轉發到「systemctl enable xinetd.service」。 [root@localhost telnet_dir]# chkconfig telnet on 注意:正在將請求轉發到「systemctl enable telnet.socket」。 Created symlink from /etc/systemd/system/sockets.target.wants/telnet.socket to /usr/lib/systemd/system/telnet.socket. [root@localhost telnet_dir]# systemctl start telnet.socket [root@localhost telnet_dir]# systemctl start xinetd # 測試telnet是否鏈接正常,默認配置不支持root登陸,最好建一個普通用戶登陸,再su到root,升級完成再userdel -r 刪除用戶便可,也能夠更改配置容許root經過telnet登陸。 [root@localhost telnet_dir]# useradd tom [root@localhost telnet_dir]# passwd tom 進行遠程telnet鏈接測試
這裏爲了更省事,防止網絡等環境問題,構建openssh的rpm包進行安裝。上面從個人網盤連接裏下載了openssh.zip文件的能夠忽略這一步,由於openssh.zip裏面已經構建好了openssh7.9p1的rpm包,直接進行升級安裝便可。
[root@localhost ~]# mkdir -p /usr/src/redhat/{SOURCES,SPECS} [root@localhost ~]# cd /usr/src/redhat/SOURCES/ [root@localhost SOURCES]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz [root@localhost SOURCES]# tar -zvxf openssh-7.9p1.tar.gz openssh-7.9p1/contrib/redhat/openssh.spec [root@localhost SOURCES]# mv openssh-7.9p1/contrib/redhat/openssh.spec ../SPECS/ [root@localhost SOURCES]# chown sshd:sshd /usr/src/redhat/SPECS/openssh.spec [root@localhost SOURCES]# cp /usr/src/redhat/SPECS/openssh.spec /usr/src/redhat/SPECS/openssh.spec_def [root@localhost SOURCES]# sed -i -e "s/%define no_gnome_askpass 0/%define no_gnome_askpass 1/g" /usr/src/redhat/SPECS/openssh.spec [root@localhost SOURCES]# sed -i -e "s/%define no_x11_askpass 0/%define no_x11_askpass 1/g" /usr/src/redhat/SPECS/openssh.spec [root@localhost SOURCES]# mkdir -p ~/rpmbuild/SOURCES/ [root@localhost SOURCES]# cp /usr/src/redhat/SOURCES/openssh-7.9p1.tar.gz ~/rpmbuild/SOURCES/ [root@localhost SOURCES]# cd /usr/src/redhat/SPECS/ [root@localhost SPECS]# rpmbuild -ba openssh.spec [root@localhost SPECS]# ll /root/rpmbuild/RPMS/x86_64/openssh-* -rw-r--r-- 1 root root 496204 1月 17 13:31 /root/rpmbuild/RPMS/x86_64/openssh-7.9p1-1.el7.x86_64.rpm -rw-r--r-- 1 root root 548576 1月 17 13:31 /root/rpmbuild/RPMS/x86_64/openssh-clients-7.9p1-1.el7.x86_64.rpm -rw-r--r-- 1 root root 2508852 1月 17 13:31 /root/rpmbuild/RPMS/x86_64/openssh-debuginfo-7.9p1-1.el7.x86_64.rpm -rw-r--r-- 1 root root 391696 1月 17 13:31 /root/rpmbuild/RPMS/x86_64/openssh-server-7.9p1-1.el7.x86_64.rpm 參考:https://blog.csdn.net/qq_42609381/article/details/82855043 # 編譯過程遇到的錯誤: 錯誤:構建依賴失敗: openssl-devel < 1.1 被 openssh-7.9p1-1.el7.x86_64 須要 解決:[root@localhost SPECS]# vim openssh.spec 註釋掉 BuildRequires: openssl-devel < 1.1 這一行 錯誤:configure: error: PAM headers not found RPM 構建錯誤: /var/tmp/rpm-tmp.OB3GHI (%build) 退出狀態很差 解決: yum install pam-devel 錯誤:壞文件:/root/rpmbuild/SOURCES/x11-ssh-askpass-1.2.4.1.tar.gz: 沒有那個文件或目錄 解決: wget http://ftp.riken.jp/Linux/momonga/6/Everything/SOURCES/x11-ssh-askpass-1.2.4.1.tar.gz cp x11-ssh-askpass-1.2.4.1.tar.gz /root/rpmbuild/SOURCES/
卸載當前版本的openssh
rpm -e `rpm -qa |grep openssh` 若是有依賴: rpm -e `rpm -qa |grep openssh` --nodeps
刪除/etc/ssh/下全部文件(注意檢查是否備份)
rm -rf /etc/ssh/*
rpm安裝openssh7.9p1
unzip openssh.zip rpm -iv --force --nodeps *.rpm
配置服務
設置開機啓動: chkconfig sshd on 編輯ssh配置文件: vim /etc/ssh/sshd_config 配置: PasswordAuthentication yes 若是要容許root用戶ssh登陸須要配置:PermitRootLogin yes 服務重啓 service sshd restart 驗證鏈接和版本 ssh -V
能夠直接恢復以前的ssh配置文件看可否成功,我這裏直接恢復以前的配置文件能夠啓動但沒法鏈接,我註釋掉GSS和PAM後能夠鏈接。
#GSSAPIAuthentication yes #GSSAPICleanupCredentials no #UsePAM yes
升級完成以後若是須要卸載telnet,進行以下步驟便可(卸載以前確保ssh鏈接已經沒有問題):
systemctl stop xinetd systemctl stop telnet.socket chkconfig xinetd off chkconfig telnet off rpm -e `rpm -qa|egrep "telnet|xinetd"` # 最後刪除以前測試telnet新建的普通用戶 userdel -r tom