查看当前版本

zale@zale-Parallels-Virtual-Platform:~$ ssh -V
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017

安装telnet 防止无法登陆

apt-get install openbsd-inetd telnetd telnet -y
/etc/init.d/openbsd-inetd restart
telnet 127.0.0.1 

安装zlib 后面需要用到

wget http://zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make -j 8
make install
如果运行“./configure --prefix=/usr/local/zlib” 出现错误 应该是gcc 的问题
#检测是否安装
cc -v
#安装
sudo apt-get install gcc

更新openssl

wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
tar zxvf openssl-1.1.1h.tar.gz
cd openssl-1.1.1h
./config shared zlib
make -j 8
make install
如果更新过程中出现 error: zlib.h:no such file or directory 请参考 这里

备份原来的openssl,创建软链接到系统位置

mv /usr/bin/openssl /usr/bin/openssl.bak 
mv /usr/include/openssl /usr/include/openssl.bak 
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl /usr/include/openssl

将openssl 的lib 库添加到系统,并使用

echo "/usr/local/lib" > /etc/ld.so.conf.d/openssl.conf
ldconfig  

查看openssl版本

root@zale-Parallels-Virtual-Platform:~/openssl-1.1.1h# openssl version -a
OpenSSL 1.1.1h  22 Sep 2020
built on: Wed Nov 25 06:24:14 2020 UTC
platform: linux-x86_64
options:  bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) 
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DZLIB -DNDEBUG
OPENSSLDIR: "/usr/local/ssl"
ENGINESDIR: "/usr/local/lib/engines-1.1"
Seeding source: os-specific

更新 openssh

备份原openssh文件,卸载原openssh
mv /etc/init.d/ssh /etc/init.d/ssh.old
cp -r /etc/ssh /etc/ssh.old
apt-get remove openssh-server openssh-client -y
安装新版本
apt-get install libpam0g-dev   -y

wget --no-check-certificate https://fastly.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz

tar zxvf openssh-8.4p1.tar.gz

cd openssh-8.4p1


./configure --prefix=/usr \
--sysconfdir=/etc/ssh \
--with-md5-passwords \
--with-pam --with-zlib \
--with-ssl-dir=/usr/local \
--with-privsep-path=/var/lib/sshd #需要指定openssl的安装路径 

make -j 8
make install 

查看安装更新效果

root@zale-Parallels-Virtual-Platform:~/openssh-8.4p1# ssh -V
OpenSSH_8.4p1, OpenSSL 1.1.1h  22 Sep 2020

还原配置文件

cd /etc/ssh
mv sshd_config sshd_config.default
cp ../ssh.old/sshd_config ./
mv /etc/init.d/ssh.old /etc/init.d/ssh
systemctl unmask ssh
systemctl restart ssh