Ubuntu 16.04 升級OpenSSH至7.7p1
因網安漏洞掃描掃出OpenSSH漏洞,需要對OpenSSH進行升級操作
安裝zlib
# 下載zlib 編譯安裝
wget http://zlib.net/zlib-1.2.11.tar.gz
tar xf zlib-1.2.11.tar.gz && cd zlib-1.2.11/
./configure && make && make install
安裝OpenSSH
需要安裝有OpenSSL 1.0.2版本,由於我的服務器已經安裝了1.0.2g,此處未進行OpenSSL的升級
# 安裝OpenSSH
wget https://fastly.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/OpenSSH-7.7p1.tar.gz
tar xf OpenSSH-7.7p1.tar.gz && cd OpenSSH-7.7p1/
# 備份啟動腳本以及配置文件
cp /etc/init.d/ssh /etc/init.d/ssh.old && cp -r /etc/ssh /etc/ssh.old
# 安裝OpenSSH
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-privsep-path=/var/lib/sshd
make && make install
編譯OpenSSH可能遇到的報錯
# 報錯: configure: error: PAM headers not found
# 解決: ubuntu: apt-get install libpam0g-dev
# centos: yum -y install pam-devel
# 報錯: configure: error: *** OpenSSL headers missing - please install first or check config.log ***
# 解決: ubuntu: apt-get install libssl-dev
# centos: yum -y install openssl-devel
查看OpenSSH版本
OpenSSH -V
systemctl超時
OpenSSH升級完成后,使用systemctl
啟動或重啟sshd服務,systemctl
會卡住90秒超時,然后報錯ssh啟動失敗,但是查看進程狀態是正常運行並且使用正常的。
上網上查找資料也沒有類似案例,無奈只能修改ssh的systemctl文件/lib/systemd/system/ssh.service
中Type
一項
Type=notify
表示當前服務啟動完畢,會通知Systemd,再繼續往下執行,判斷是編譯安裝后的ssh服務正常啟動后,沒有給systemctl返回啟動成功的信號。
將Type=notify
修改為Type=simple
,這樣systemctl不會等待ssh返回的信號。執行systemctl daemon-reload
並重啟sshd進程可以解決systemctl超時的問題