CentOS7下rpm包安裝方式升級至OpenSSH9.6p1安全版本
1.備份當前的YUM倉庫配置檔案,以防需要恢復:
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2.配置網易yum源:
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo
3.清除YUM快取並使新的配置生效:
yum clean all yum makecache yum update
4.準備CentOS7編譯環境
yum groupinstall -y "Development Tools" yum install -y imake rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel
5.下載編譯打包的shell指令碼包並解壓
GitHub地址:https://github.com/boypt/openssh-rpms
wget https://github.com/boypt/openssh-rpms/archive/refs/heads/main.zip
解壓
unzip main.zip -d /opt cd /opt/openssh-rpms-main/
6.修改pullsrc.sh指令碼引數
指令碼23行修改為:source ./version.env
檢查指令碼中wget 是否有忽略 SSL 證書驗證,選項為:--no-check-certificate (示例:wget --no-check-certificate $OPENSSLMIR/$OPENSSLSRC)
新版本一般不用修改,預設已新增
檢查openssh原始碼中有沒有ssh-copy-id
vim /opt/openssh-rpms-main/el7/SPECS/openssh.spec
搜尋相關ssh-copy-id 引數,能搜到即有,新版本預設都有
7.修改version.env,將變數中的包修改為要升級的版本包
下載升級的版本包放到downloads目錄下
8.編譯打包
./compile.sh
執行結果如下:
9.升級測試
升級前備份配置檔案/etc/ssh/sshd_config
cp /etc/ssh/sshd_config{,.bak}
安裝rpm包進行升級
# cd /opt/openssh-rpms-main/el7/RPMS/x86_64/ # yum localinstall ./* # ssh -V OpenSSH_9.6p1, OpenSSL 1.1.1w 11 Sep 2023
10.升級後重啟sshd服務問題處理
1)服務重啟失敗
# systemctl restart sshd Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
提示許可權不正確,私鑰檔案許可權太開放,解決方法:
chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key
2)root登入被拒絕
日誌內容:
升級後原先得/etc/ssh/sshd_config 檔案被覆蓋,不允許root登入,解決方法:
vim /etc/ssh/sshd_config
PermitRootLogin yes ## 開啟這行註釋,儲存退出重啟sshd服務即可