linux系统将OpenSSH升级到最高版本

本文介绍了在虚拟机中发现OpenSSH安全漏洞后,如何直接通过SSH连接升级OpenSSH到最新版本9.3p2以及openssl到1.1.1,包括升级步骤、依赖检查、可能遇到的错误及解决方法,同时强调了升级风险和注意事项。
摘要由CSDN通过智能技术生成

一、背景:

公司安全扫描到主机的OpenSSH安全漏洞,由于是虚拟机只能由自己修复,很多OpenSSH的漏洞厂商都没有提供补丁,只能通过禁用scp或者端口的方式临时解决,但是后面使用就不方便了,而且也不安全,所以直接将OpenSSH升级到现在的最高版本openssh-9.3p2,ssl升级到1.1.1。

 二、准备工作:

升级OpenSSH是有风险的,失败会导致不能通过SSH连接到主机,所以最好先按照telnet的相关工具,通过telnet连接主机进行SSH升级操作,因为此次操作的是虚拟机,跟公司的机房老师沟通,即使升级失败,他们也是可以连接上主机的,所有我就没再按照telnet的相关组件,直接通过SSH连接到主机进行的升级。升级前可以先看下报错处理章节,方便安装过程中有问题解决。

升级SSH需要先查看gcc、pcre、zlib  perl是否安装使用以下命令可以查看:

gcc --version、rpm -qa pcre、yum list installed | grep zlib*、perl -version。查看SSH版本 ssh -V, 查看ssl版本openssl version

 

gcc包没有的请参考这篇文章:https://blog.51cto.com/u_15064655/4818120

perl没有的:

下载地址:https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz,将包上传到服务器上,然后执行一下命令:

tar -xzf perl-5.34.0.tar.gz

 cd perl-5.34.0

./Configure -des -Dprefix=$HOME/localperl

make 

make test 

make install

注意:

1、通过SSH连接主机升级时,不要关闭SSH连接,再升级过程中关闭了以后可能就连不上了;

2、SSH升级依赖于SSL,对SSL的版本有要求,要先按照SSL再按照SSH;

三、开始安装:

1、下载openssl、openssh、zlib包

下载openssl
https://www.openssl.org/source/openssl-1.1.1t.tar.gz
下载openssh
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p2.tar.gz
下载zlib
http://www.zlib.net/zlib-1.2.13.tar.gz

按照顺序是zlib库-> openssl -> openssh的顺序安装;

2、安装zlib

tar -zxvf zlib-1.2.13.tar.gz   -C /usr/local/src

cd zlib-1.2.13
./configure --prefix=/usr/local/zlib &&?make?-j 4?&&?make?install


3、安装ssl

tar -zxvf openssl-1.1.1t.tar.gz -C /usr/local/src/
cd /usr/local/src/openssl-1.1.1t

./config --prefix=/usr/local/ssl -d shared  #编译时可能会报错,请看错误模块

make -j 4 && make install

 echo '/usr/local/ssl/lib' >> /etc/ld.so.conf

ldconfig -v

/usr/local/ssl/bin/openssl version -a # 查询这个目录下openssl版本已是1.1.1p

4、安装ssh

tar -zxvf openssh-9.3p1.tar.gz -C /usr/local/src/

先备份:mv /etc/ssh /etc/ssh.bak
cd  /usr/local/src/openssh-9.3p2

#指定ssl和zlib安装位置
./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
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh 
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

安装完成,查看版本ssh -V

5、重启sshd服务

systemctl restart sshd

systemctl status sshd

四、报错处理:

1、执行ssl的./config --prefix=/usr/local/ssl -d shared编译时报错:

Operating system: x86_64-whatever-linux2 You need Perl 5.

你需要安装perl-5.34.0.tar.gz

下载https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz

tar -xzf perl-5.34.0.tar.gz
 cd perl-5.34.0
./Configure -des -Dprefix=$HOME/localperl
make 
make test 
make install

2、ssl 执行  make -j 4 && make install报错
sh: pod2html: command not found
没找到原因,但是暂时没找到有什么影响,测试ssl是正常的。

3、重启ssh服务报错:

Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.        

使用/usr/sbin/sshd -T查看
是/etc/ssh/ssh_host_ed25519_key这个文件的权限太大了,去所在目录下执行 chmod 600 ssh_host_ed25519_key 命令修改文件权限,重启可能还报错,再用-T看下,还有其他的文件权限太大。
chmod 600 ssh_host_rsa_key、chmod 600 ssh_host_ecdsa_key、 chmod 600 ssh_host_ed25519_key基本上这三个。

4、重启报错:Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details. 

用sshd -t看到报错信息为

/etc/ssh/sshd_config line 80: Unsupported option GSSAPICleanupCredentials

/etc/ssh/sshd_config line 96: Unsupported option UsePAM

vi /etc/ssh/sshd_config
把#GSSAPIAuthentication yes  、#GSSAPICleanupCredentials no  把这两个禁掉
#UsePAM no也禁掉

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值