离线升级openssh

1. 相关地址

openssh下载地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/

openssl下载地址:https://www.openssl.org/source/

zlib下载地址:http://www.zlib.net/

2. 检查版本

openssl version -a
ssh -V
ldconfig -v (有个软连接)

检查前置条件

yum install -y gcc
yum install -y perl-CPAN (openssl 3.0高版本需要这个IPC/Cmd.pm模块,目前选择openssl-1.1.1o版本没有这个也能安装成功)
yum install -y openssl-devel

3. 升级openssh

3.1 下载并解压

wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1o.tar.gz
wget http://www.zlib.net/zlib-1.2.3.tar.gz

tar zxvf openssh-9.0p1.tar.gz
tar zxvf openssl-1.1.1o.tar.gz
tar zxvf zlib-1.2.3.9.tar.gz

注:如果zlib-1.2.3版本下载不到可以去github上去下载对应版本。

3.2 编译安装zlib

github:https://github.com/madler/zlib/tags

cd zlib-1.2.3.9
 
./configure --prefix=/usr/local/zlib

make && make install
 
echo '/usr/local/zlib/lib' >> /etc/ld.so.conf

ldconfig -v

# 查看是否安装成功,要包含下面👇🏻这三个目录
[root@iZ2zefotebvn5yxc31tdqrZ ~]# ls /usr/local/zlib/
include  lib  share

3.3 编译安装openssl

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

3.4 升级openSSH

注:停止可能会断开这个要,需要本地直接连接或者Telnet连接
停止ssh服务
systemctl stop sshd
备份ssh配置文件
cp -r /etc/ssh /etc/ssh.old

卸载rpm包

rpm -qa | grep openssh
# 卸载
rpm -e --nodeps openssh-server-7.4p1-21.el7.x86_64
rpm -e --nodeps openssh-7.4p1-21.el7.x86_64
rpm -e --nodeps openssh-clients-7.4p1-21.el7.x86_64
rpm -qa | grep openssh

3.5 安装openssh

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

3.6 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

3.7 备份文件和copy新文件

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
ssh服务必须开机自启动,因此要进行一些设置
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
重启sshd服务
systemctl restart sshd
systemctl enable sshd
查看sshd服务状态
systemctl status sshd -l
验证ssh版本
ssh -V
--重启服务器,测试ssh
reboot

 

posted @ 2022-08-24 10:26  kerwin-  阅读(720)  评论(0编辑  收藏  举报