Centos7 离线升级openssh到9.3p1

发布时间 2023-07-27 16:55:37作者: 苦逼yw

参考:https://blog.csdn.net/qq_29768197/article/details/125048720

参考:https://blog.csdn.net/weixin_46739058/article/details/129189927

 

1、官方下载地址: http://www.zlib.net/        zlib-1.2.12.tar.gz

wget http://www.zlib.net/zlib-1.2.13.tar.gz

 2、官方下载地址:https://www.openssl.org/source/        openssl-1.1.1u.tar.gz

wget https://www.openssl.org/source/openssl-1.1.1u.tar.gz

3、官方下载地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/                   openssh-9.3p1.tar.gz

wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz

 4、解压

tar zxvf /root/zlib-1.2.13.tar.gz
tar zxvf /root/openssl-1.1.1u.tar.gz
tar zxvf /root/openssh-9.3p1.tar.gz

5、安装gcc(没有就安装)

参考:https://blog.csdn.net/vipee1/article/details/127264883

 6、编译安装zlib

cd zlib-1.2.13
 
./configure --prefix=/usr/local/zlib
 
 
make && make install
 
echo '/usr/local/zlib/lib' >> /etc/ld.so.conf  
ldconfig -v

7、编译安装openssl

cd  openssl-1.1.1u 
 
./config --prefix=/usr/local/ssl -d shared
 
make && make install   (时间比较长,切勿打断)
 
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v

8、编译安装openssh

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

9、配置ssh,备份原有文件,并将新的配置复制到指定目录

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
 
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
 
chmod +x /etc/init.d/sshd
 
chkconfig --add sshd
 
chkconfig sshd on
 
chmod 600 /etc/ssh/ssh_host_rsa_key
 
chmod 600 /etc/ssh/ssh_host_ecdsa_key
 
chown -R root.root /var/empty/sshd
 
chmod 744 /var/empty/sshd

10、卸载系统里原有Openssh(一般有三个包,全部卸载)

rpm -qa | grep openssh
根据上面查询出的结果,卸载系统里原有Openssh(一般有三个包,全部卸载)
rpm -e --nodeps  xxxxxxxxxx
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,确保没有回显
rpm -qa | grep openssh

11、重启服务,验证

重启sshd服务
systemctl restart sshd

验证ssh版本
ssh -V