centos升级openssh到openssh-8.4p1版本

项目中漏洞扫描到服务器的openssh 版本过低 需要升级到7.0或更高的版本

记录一下

大的版本升级需要先把之前的旧版本删除掉 重新装新的高版本 如果删除掉没有安装好 那么服务器就不能远程连接了 所以 建议先在云管理平台做服务器的镜像备份文件,然后先安装telnet 使用telnet 连接操作服务器。(如果准备安装telnet请安装文章末尾的转载文件)

我没有安装telnet,我是在本地打开了多个连接窗口,这个不行,换另一个。。。。。

首先新建个目录吧 我也是百度了很多博客 基本都是新建的data/tools


mkdir -p /data/tools

然后进入到这个文件夹 如下图

关于这俩解压包 请点击链接下载

openssh版本openssh-8.4p1.tar.gz:https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

openssl版本openssl-1.0.2h.tar.gz:https://ftp.openssl.org/source/

或者点击百度网盘

链接:https://pan.baidu.com/s/1SBLfZWhTZn9WUbr0GS7f9g  密码:ry94

升级需要一些组件 和编译相关的 截图没有截全 等安装完成即可

yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel

安装pam和zlib

yum install  -y pam* zlib*

备份这俩文件

[root@test-file tools]# mv /usr/bin/openssl /usr/bin/openssl_bak
[root@test-file tools]# 
[root@test-file tools]# 
[root@test-file tools]# mv /usr/include/openssl /usr/include/openssl_bak
[root@test-file tools]# 

然后 tar命令解压(ssl 和ssh两个包 )

tar -zxvf openssl-1.0.2r.tar.gz

先来安装ssl 进入到ssl的目录

进去之后 编译安装 命令执行后 耐心等待安装即可

./config shared && make && make install

安装完成后 使用命令 echo $? 查看是否成功 0表示可以

下面2个文件或者目录做软链接 (刚才前面的步骤mv备份过原来的)

[root@test-file openssl-1.0.2h]# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
[root@test-file openssl-1.0.2h]# 
[root@test-file openssl-1.0.2h]# 
[root@test-file openssl-1.0.2h]# ln -s /usr/local/ssl/include/openssl /usr/include/openssl
[root@test-file openssl-1.0.2h]# 
[root@test-file openssl-1.0.2h]# 

加载新配置 并确认版本

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
 
/sbin/ldconfig

ssl完成后 再进入到ssh的目录里去安装

安装之前 先移除之前的ssh

[root@test-file openssh-8.4p1]# rm -rf /etc/ssh/*
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

同样的 echo $? 查看结果

随后 修改 /etc/ssh/sshd_config 配置文件里的这三个值

改为 PermitRootLogin yes

UseDNS no

UsePAM no 如图

然后回到openssht8.4的解压的包中拷贝一些文件到目标位置(如果目标目录存在就覆盖)

[root@test-file openssh-8.4p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# chmod +x /etc/init.d/sshd
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# chkconfig --add sshd
[root@test-file openssh-8.4p1]# 
[root@test-file openssh-8.4p1]# systemctl enable sshd

移走原来的systemd管理的sshd文件 否则影响sshd重启

[root@test-file openssh-8.4p1]# mv  /usr/lib/systemd/system/sshd.service  /data/

设置开机自启

[root@test-file openssh-8.4p1]# chkconfig sshd on

最后 重启

[root@test-file openssh-8.4p1]# /etc/init.d/sshd restart

也可以使用 以下命令停止和启动

systemctl stop sshd
 
systemctl start sshd
 
systemctl restart sshd

然后 这个窗口先不要关闭 重新打开一个新的窗口连接服务器

ssh 连接 报错如下

打开自己的known_hosts 文件中 和连接的ip项目的内容都删除掉 并重新ssh 连接

转载地址:centos7 升级openssh到openssh-8.0p1版本

猜你喜欢

转载自blog.csdn.net/zianY/article/details/109079476