1. 程式人生 > 實用技巧 >Centos7 openssh 離線升級8.4

Centos7 openssh 離線升級8.4


title: Centos7 openssh 離線升級8.4

openssh 低版本存在漏洞,所以需要升級到最新版,由於客戶是離線環境所以採用離線安裝。

下載依賴openssl、zlib、openssh

在有網路的主機上下載依賴 拷貝到目標伺服器

wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/openssh-8.4p1.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz

解壓升級包

tar  --no-same-owner -zxvf zlib-1.2.11.tar.gz
tar  --no-same-owner -zxvf openssh-8.4p1.tar.gz
tar  --no-same-owner -zxvf openssl-1.1.1g.tar.gz

編譯安裝zlib

cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make && make install

編譯安裝openssl

cd openssl-1.1.1g
./config --prefix=/usr/local/ssl -d shared
make && make install
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v

安裝openssh

cd openssh-8.4p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install

sshd_config檔案修改

echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config

備份原有檔案,並將新的配置複製到指定目錄

mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
mv /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub

啟動sshd

service sshd restart
ssh -V
# OpenSSH_8.4p1, OpenSSL 1.1.1g  21 Apr 2020