晓张 XiaoZhang.net http://www.xiaozhang.net [分享] [RSS]

日志

将CentOS7 OpenSSH升级到8.4p1版本

已有 608 次阅读2021-1-13 09:35 |个人分类:IT世界| 晓张, OpenSSH

 

 

CentOS7 OpenSSH升级到8.4p1版本

 

 

  随着信息安全要求越来越高,生产系统在正式上线前都会先进行漏洞扫描检查,而我们在使用CentOS操作系统时常常用的是默认SSH服务版本,漏洞扫描基本上是一扫一个准,所以本次就来谈谈SSH服务的升级。

 

  升级前主机软件环境(图1):

  操作系统版本:CentOS 7.3

  OpenSSL版本:OpenSSL 1.0.1e-fips 11 Feb 2013

  OpenSSH版本:OpenSSH_6.6.1p1

1

 

  升级后主机软件环境(图2):

  操作系统版本:CentOS 7.3

  OpenSSL版本:OpenSSL 1.1.1i 8 Dec 2020

  OpenSSH版本:OpenSSH_8.4p1

2

 

   本次升级的OpenSSHOpenSSL是目前官方最新版本,软件包信息如下。  
    openssh-8.4p1.tar                 2020-09-27

    openssl-1.1.1i.tar.gz              2020-12-08

 

  软件包官方下载地址:

  https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

  https://ftp.openssl.org/source/

 

  在升级OpenSSHOpenSSL之前,需要先安装一些软件包(图3),这里提一句,升级在2019年的openssl-1.0.2r.tar  OpenSSL包时不需要安装perl-core包,这是一个不同点。

[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel

[root@localhost ~]# yum install -y pam* zlib*

[root@localhost ~]# yum install -y perl perl-core

3

 

  在升级OpenSSL前,我们将现有的openssl文件(图4)和openssl目录(图5)作了备份,以备不时之需。

[root@localhost ssh]# mv /usr/bin/openssl /usr/bin/openssl_bak

4

[root@localhost ssh]# mv /usr/include/openssl /usr/include/openssl_bak

5

 

  然后将OpenSSHOpenSSL两个升级包复制到系统中,放哪里都可以,能保证执行就可以了。

 

  编译安装新版本的OpenSSL

  先将OpenSSL软件包解压

  [root@localhost ~]# tar -xvf openssl-1.1.1i.tar.gz

  进入解压后的OpenSSL目录,进行配置、编译、编译测试和安装几个步骤,命令我是一条一条执行,每一条执行完成后使用“echo $?”验证返回值是否为“0”,执行成功。

[root@localhost openssl-1.1.1i]# ./config

[root@localhost openssl-1.1.1i]# make

[root@localhost openssl-1.1.1i]# make test

[root@localhost openssl-1.1.1i]# make install

 

  OpenSSL安装完成后,建立OpenSSL的文件和目录软链接

[root@localhost openssl-1.1.1i]# ln -s /usr/local/bin/openssl /usr/bin/openssl

6

[root@localhost openssl-1.1.1i]# ln -s /usr/local/include/openssl /usr/include/openssl

7

 

  然后执行以下2条命令加载新配置(图8

[root@localhost openssl-1.1.1i]# echo "/usr/local/lib64" >> /etc/ld.so.conf

[root@localhost openssl-1.1.1i]# /sbin/ldconfig

8

 

  此时可查看OpenSSL安装后的版本,是否为1.1.1i(图9

[root@localhost openssl-1.1.1i]# openssl version

9

 

  OpenSSL升级成功后,接下来就是升级安装OpenSSH

  升级安装之前,先将现有的ssh配置文件和目录删除。

[root@localhost ssh]# rm -rf /etc/ssh/*

 

  解压openssh升级包。

[root@localhost ssh]# tar -xvf openssh-8.4p1.tar.gz

 

  进入OpenSSH解压后的目录,进行配置(图10)、编译和安装

 [root@localhost openssh-8.4p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/include/openssl  --with-ssl-dir=/usr/local/lib64   --with-zlib   --with-md5-passwords   --with-pam

10

[root@localhost openssh-8.4p1]# make

[root@localhost openssh-8.4p1]# make install

 

  从openssh-8.4p1解压的包中拷贝相关文件到目标位置(如果目标目录存在就覆盖)(图11

[root@localhost openssh-8.4p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd

[root@localhost openssh-8.4p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

[root@localhost openssh-8.4p1]# chmod +x /etc/init.d/sshd

[root@localhost openssh-8.4p1]# chkconfig --add sshd

[root@localhost openssh-8.4p1]# systemctl enable sshd

11

 

  把原先的systemd管理的sshd文件删除或者移走,不移走的话会影响重启sshd服务。

[root@localhost openssh-8.4p1]# mv /usr/lib/systemd/system/sshd.service ~

12

 

  设置sshd服务开机启动(图13

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

13

 

  查看OpenSSH升级后的版本,是否为8.4p1(图14

[root@localhost openssh-8.4p1]# ssh –V

14

 

  现在OpenSSLOpenSSH都已升级完成,我们需要连接测试,在这之前可先将selinux关闭,可使用“setenforce 0”来临时关闭selinux,也可采用修改配置文件参数永久关闭selinux(图15)。

[root@localhost selinux]# vi /etc/selinux/config

  将“SELINUX=enforcing”修改为“SELINUX=disabled”。

15

 

  OpenSSH升级使用后,使用的sshd config默认配置,此配置是禁止root远程登陆的,只有先用普通帐号登陆后,再su切换到root帐号。若需要开启root远程登陆,可修改sshd_config配置文件,操作如下。

[root@localhost ssh]# vi /etc/ssh/sshd_config

增加一条配置(图16):PermitRootLogin yes

16

 

收藏 分享 转发到微博 举报

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

成都宠物论坛|手机版|成都宠物网搜索|百度|谷歌|宠我网 ( 蜀ICP备07500266号 

GMT+8, 2024-4-18 16:34 , Processed in 0.113144 second(s), 16 queries .

© 2007 By www.Petovo.com Some rights reserved

回顶部