openssh升級7.4p1至8.4p1、openssl升級至openssl-1.1.1h

不是書本的小明發表於2020-12-04

**

openssh升級7.4p1至8.4p1、openssl升級至openssl-1.1.1h

**
升級準備:
下載安裝包
https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz
https://www.openssl.org/source/openssl-1.1.1h.tar.gz
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz

一、指令碼只適用於Centos7系列 升級之前 ssh -V 檢視一下 SSH的版本 >=OpenSSH_7.4p1
系統版本CentOS7.7、Openssh_7.4p1
vim opensshUpgrade.sh

#!/bin/bash

# 手動上傳安裝包 至 /opt目錄
cd /opt

# 解壓安裝包,我習慣將安裝包解壓到/usr/local/src
tar xf openssh-8.4p1.tar.gz -C /usr/local/src/
tar xf openssl-1.1.1h.tar.gz -C /usr/local/src/
tar xf zlib-1.2.11.tar.gz -C /usr/local/src/

# 安裝zlib-1.2.11.tar.gz
yum -y install gcc gcc-c++ kernel-devel
cd /usr/local/src/zlib-1.2.11/
./configure --prefix=/usr/local/zlib && make -j 4 && make install

# 安裝 openssl-1.1.1h.tar.gz
cd /usr/local/src/openssl-1.1.1h/
./config --prefix=/usr/local/ssl -d shared
make -j 4 && make install
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v

# 安裝openssh-8.4p1.tar.gz
mv /etc/ssh /etc/ssh.bak
cd /usr/local/src/openssh-8.4p1/
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib 
make -j 4 && make install

# sshd_config檔案修改
echo "X11Forwarding yes" >> /etc/ssh/sshd_config
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config                
echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config
echo "UseDNS no" >> /etc/ssh/sshd_config
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config

# 備份 /etc/ssh 原有檔案,並將新的配置複製到指定目錄
mv /usr/sbin/sshd /usr/sbin/sshd.bak &>/dev/null
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak &>/dev/null
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh 
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak &>/dev/null
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

# 啟動 sshd 並將其加入開機自啟
systemctl stop sshd.service &>/dev/null
rm -rf /lib/systemd/system/sshd.service 
systemctl daemon-reload
cp /usr/local/src/openssh-8.4p1/contrib/redhat/sshd.init /etc/init.d/sshd
/etc/init.d/sshd restart
chkconfig --add  sshd
systemctl status sshd| grep  "Active: active (running)"

if [ $? -eq 0 ]; then
	echo -e "\033[32m[INFO] OpenSSH upgraded to 8.4p1  successfully!\033[0m"
else
	echo -e "\033[31m[ERROR] OpenSSH upgraded to 8.4p1 faild!\033[0m"
fi

二、手動將下載的三個tar.gz包和指令碼opensshUpgrade.sh上傳至/opt目錄下

三、執行以下命令 即可升級完成(升級指令碼中會依賴yum源去安裝一些編譯器、依賴)

cd /opt
chmod +x opensshUpgrade.sh
./opensshUpgrade.sh
執行命令即可完成升級
四、執行 ssh -V 檢視升級後的版本 如果輸出為 OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020 表示升級完成
升級完成效果圖
升級過程中,有任何問題、報錯 請留言至610472802@qq.com 看到會及時回覆

相關文章