前言
收到通知說服務(wù)器組件存在漏洞
服務(wù)器版本:CentOS 7.9.2009 x86_64
目前SSH版本:OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
使用yum
升級yum update -y openssh
最新版本還是:OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
接下來嘗試手動升級
前置操作
為了避免升級過程中出現(xiàn)的意外導(dǎo)致服務(wù)器無法進(jìn)行連接,建議對重要的內(nèi)容先進(jìn)行備份
創(chuàng)建快照
在主機(jī)服務(wù)商那里為主機(jī)創(chuàng)建快照,防止最糟糕的事情發(fā)生
備份配置文件
備份 /etc/pam.d/sshd 文件
[root@bogon ~]# mv /etc/pam.d/sshd /etc/pam.d/sshd-bak
[root@bogon ~]# ls -l /etc/pam.d/sshd*
-rw-r--r-- 1 root root 904 Nov 25 2021 /etc/pam.d/sshd-bak
安裝telnet
升級過程中會卸載舊版本 ssh
導(dǎo)致遠(yuǎn)程無法連接,所以先安裝一個 telnet
安裝
rpm -q telnet-server
#檢查是否安裝了telnet服務(wù)端
rpm -q telnet
#檢查是否安裝了telnet客戶端
提示package telnet-server is not installed
表示未安裝
yum install telnet-server -y
#安裝telnet服務(wù)端
yum install telnet -y
#安裝telnet客戶端
啟動
systemctl enable telnet.socket
#設(shè)置開機(jī)啟動該
systemctl start telnet.socket
#打開服務(wù)
防火墻開放23
端口
使用telnet ip地址
進(jìn)行連接登錄
允許root登錄
默認(rèn)系統(tǒng)不允許root用戶使用telnet遠(yuǎn)程登陸
echo 'pts/0' >>/etc/securetty
echo 'pts/1' >>/etc/securetty
可能還需要添加下 pts/3 和 pts/4
輸入正確的密碼還是不能登錄
主機(jī)端執(zhí)行:tail /var/log/secure
看到了access denied: tty 'pts/3' is not secure !
再添加一個
echo 'pts/3' >>/etc/securetty
重啟了telnet
后再登錄一切正常了
開始升級
執(zhí)行下方操作前,請確認(rèn)telnet外部連接正常
下載升級包
可用版本下載
http://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/
http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
地址中列出了可用的版本升級文件,我本次計(jì)劃升級到9.3
,使用的是openssh-9.3p1.tar.gz
可以使用本地網(wǎng)絡(luò)下載壓縮包后上傳到服務(wù)器opt
目錄,也可以在服務(wù)器內(nèi)執(zhí)行命令下載
cd /opt/
wget http://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
解壓
tar -zxvf openssh-9.3p1.tar.gz
cd openssh-9.3p1
安裝依賴
安裝
務(wù)必確認(rèn)已快照,已配置telnet
備份配置文件
cp /etc/ssh/sshd_config sshd_config.backup
cp /etc/pam.d/sshd sshd.backup
卸載舊版本
rpm -e --nodeps `rpm -qa | grep openssh`
安裝依賴
yum -y install gcc pam-devel zlib-devel openssl-devel
編譯配置
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-zlib --with-md5-passwords --with-pam
編譯安裝
make && make install
調(diào)整文件權(quán)限
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
復(fù)制配置文件
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
chmod u+x /etc/init.d/sshd
還原配置文件
mv ../sshd.backup /etc/pam.d/sshd
mv ../sshd_config.backup /etc/ssh/sshd_config
添加開機(jī)啟動
chkconfig --add sshd
chkconfig sshd on
重啟sshd
systemctl restart sshd
#重啟
ssh -V
#查看版本
成功升級到OpenSSH_9.3p1, OpenSSL 1.0.2k-fips 26 Jan 2017
登錄驗(yàn)證,如果出錯,可以查看踩坑記錄
踩坑記錄
賬號密碼錯誤
未開啟root登錄
檢查/etc/ssh/sshd_config
是否存在
PermitRootLogin yes
賬戶鎖定
使用正確的賬號密碼登錄,始終返回賬號密碼錯誤
檢查root
賬戶是否被鎖定 cat /etc/shadow | grep root
root:$6$88xxxxxxxxxxx:::
如果密碼前有兩個!!
(如root:!!$6$884zQxxx)則表示鎖定
解除root
鎖定passwd -u root
Unlocking password for user root.
passwd: Success
WinSCP無法連接
連接被關(guān)閉了
無法初始化SFTP協(xié)議。主機(jī)是SFTP服務(wù)器嗎?
修改連接配置,將文件協(xié)議從SFTP
修改為SCP
PS:升級了兩臺服務(wù)器,只有一臺有這個問題.這不是一個很好的解決方案,但是我沒找到原因(大??梢灾刚?
無法登錄
在服務(wù)器中查看狀態(tài)service sshd status
得到了下面得到Failed
記錄
Apr 21 09:01:15 bogon sshd[542]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=x.x.x.x user=root
Apr 21 09:01:15 bogon sshd[542]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Apr 21 09:01:16 bogon sshd[542]: Failed password for root from x.x.x.x port 56012 ssh2
Apr 21 09:01:24 bogon sshd[542]: Accepted password for root from x.x.x.x port 56012 ssh2
以下解決方案摘自阿里云
檢查這三個配置文件,是否限制了登錄(如pam_succeed_if.so uid >= 1000
)文章來源:http://www.zghlxwxcb.cn/news/detail-688617.html
文件 | 功能說明 |
---|---|
/etc/pam.d/login | 控制臺(管理終端)對應(yīng)的配置文件。 |
/etc/pam.d/sshd | SSH遠(yuǎn)程登錄對應(yīng)的配置文件。 |
/etc/pam.d/system-auth | 系統(tǒng)全局配置文件 |
如果有限制,注釋相關(guān)配置,或者修改策略文章來源地址http://www.zghlxwxcb.cn/news/detail-688617.html
auth required pam_succeed_if.so uid <= 1000 # 修改策略
# auth required pam_succeed_if.so uid >= 1000 # 注釋相關(guān)配置
到了這里,關(guān)于記一次手動將OpenSSH從7.4升級到9.3的過程的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!