CentOS7下升級安裝openssh7.5p1的踩過的那些坑

背景說明

最近公司項目上客戶提供的云主機(jī),被云服務(wù)器提供商掃描告知有許多openssh漏洞,一下想到的就是升級到最新版本,可是大家都知道openssh是一個非常重要的服務(wù),實在不敢隨意升級于是就在虛擬機(jī)里面進(jìn)行了多次模擬演練,結(jié)果都失敗了。

經(jīng)過一番百度和不斷的模擬對比,對升級過程進(jìn)行一步一步的仔細(xì)探索,終于將openssh升級到最新版7.5p1,其中sshd和sftp-server均正常功能,至于x11功能未進(jìn)行測試。

升級中遇到的坑

遇到問題多看日志,仔細(xì)分析,由于修復(fù)漏洞的時間比較緊,當(dāng)時沒有仔細(xì)分析日志,待安裝完成后,再重新進(jìn)行問題重現(xiàn)的過程中仔細(xì)查看分析日志才知道原來都是一些配置錯誤。

  • 升級過程中ssh不會因為重啟斷開,一定要在啟一個窗口測試可以登錄之后再關(guān)閉當(dāng)前的ssh鏈接,避免升級不成功導(dǎo)致不能遠(yuǎn)程連接到服務(wù)器。
  1. 升級成功后不能使用systemctl start sshd啟動程序
    原因分析:
    1、編譯安裝時未啟用某些功能支持導(dǎo)致使用舊配置文件無法啟動sshd,如GSSAPIAuthentication、UsePrivilegeSeparation
    2、配置文件權(quán)限錯誤,導(dǎo)致無法啟動,如:ssh_host_rsa_key、ssh_host_ecdsa_key、ssh_host_ed25519_key
  2. 升級成功后輸入密碼無法登錄系統(tǒng)
    原因分析:
    1、未對配置文件進(jìn)行修改,openssh7.5默認(rèn)配置不允許使用root登錄系統(tǒng)
    2、pam配置文件錯誤或丟失
    3、配置文件中未啟用pam選項:UsePAM

升級準(zhǔn)備

在升級過程中,測試了源碼編碼及使用源碼創(chuàng)建rpm進(jìn)行升級,此文先將源碼編譯升級進(jìn)行講解,之后再講解如何使用rpmbuild命令創(chuàng)建rpm進(jìn)行安裝
(1) 下載源碼包,下載地址如下

openssh-7.5p1 下載地址:
https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz
其他版本openssh下載地址:
https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
cd /opt
wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz

(2) 備份原openssh配置文件

cp /etc/ssh{,.old_$(date '+%s')}
cp /etc/pam.d/sshd{,.old_$(date '+%s')}

(3) 安裝依賴

yum -y install  gcc automake zlib-devel openssl-devel pam-devel

(4) 解壓編譯安裝

tar xf openssh-7.5p1.tar.gz
cd openssh-7.5p1
./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin \
      --sysconfdir=/etc/ssh --mandir=/usr/share --docdir=/usr/share /doc/openssh75 \
      --with-pam --with-md5-passwords --with-zlib --with-ssl
make  && make install

(5) 修改配置文件sshd_config,如果無法遠(yuǎn)程,請多查看報錯根據(jù)報錯來修改配置文件。下面是推薦可用參數(shù)

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
Subsystem   sftp    /usr/libexec/sftp-server

(6) 重啟服務(wù)

systemctl restart sshd

安裝腳本:

mkdir /opt/backup
mv /etc/ssh /opt/backup
cp /etc/pam.d/sshd /opt/backup
yum -y install gcc automake  openssl-devel  zlib-devel pam-devel
tar xf openssh-7.5p1.tar.gz
cd openssh-7.5p1
./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc/ssh --mandir=/usr/share --docdir=/usr/share/doc/openssh75 --with-pam --with-md5-passwords --with-zlib --with-ssl
make
mv sshd_config{,old_$(date '%s')}
cat >> sshd_config << SSHDEOF
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
Subsystem   sftp    /usr/libexec/sftp-server
SSHDEOF
cp contrib/redhat/sshd.init /etc/init.d/sshd 
chmod 755 /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
rpm  -qa | grep openssh | xargs rpm -e --nodeps
cp  /opt/backup/sshd   /etc/pam.d/
make install
service sshd start
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. 寫在前面 在工作中經(jīng)常會碰到系統(tǒng)安全檢測之類的事情,由于常用的發(fā)行版如CentOS自帶的openssh版本都...
    天之藍(lán)色閱讀 3,491評論 0 3
  • SSH服務(wù)器dropbearAIDEsudoTCP-WrapperPAM認(rèn)證機(jī)制 一、SSH服務(wù)器: 服務(wù)器端:s...
    哈嘍別樣閱讀 1,320評論 0 0
  • 一、用戶帳號和環(huán)境……………………………………………………………. 2 二、系統(tǒng)訪問認(rèn)證和授權(quán)…………………………...
    大福技術(shù)閱讀 6,129評論 0 5
  • RedHat Linux下升級 SSH 服務(wù) 當(dāng) Telenet 已經(jīng)漸漸退出歷史舞臺后,SSH ( Securi...
    孫玨公子閱讀 3,520評論 1 1
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,534評論 19 139

友情鏈接更多精彩內(nèi)容