CENTOS7 升级OpenSSL到OpenSSL 1.1.1i,升级openssh到 OpenSSH_8.3p1版本

环境介绍


(操作前配置好yum)

整个过程不需要卸载原先的openssl包和openssh的rpm包。不影响我们的操作

本文的环境都是系统自带的openssh,没有经历过手动编译安装方式。如果之前有手动编译安装过openssh,请参照本文自行测试是否能成功。

centos7.6升级后的效果

 安装依赖包


升级需要几个组件,有些是和编译相关的等

[root@meiyun11 app]#  yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package gcc-c++-4.8.5-44.el7.x86_64 already installed and latest version
Package glibc-2.17-317.el7.x86_64 already installed and latest version
Package 1:make-3.82-24.el7.x86_64 already installed and latest version
Package autoconf-2.69-11.el7.noarch already installed and latest version
Package 1:openssl-1.0.2k-19.el7.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.2k-19.el7.x86_64 already installed and latest version
Package pcre-devel-8.32-17.el7.x86_64 already installed and latest version
Package pam-devel-1.1.8-23.el7.x86_64 already installed and latest version
Nothing to do
 

 安装pam和zlib等(后面的升级操作可能没用到pam,安装上也没啥影响,如果不想安装pam请自行测试)

 yum install  -y pam* zlib*

 

下载openssh包和openssl的包

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


我们都下载最新版本,下载箭头指的包

https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

 开始安装openssl


个人习惯把安装包或者工具之类的放下面目录。根据个人喜好随便放,不影响安装

上传,解压如下


 

[root@meiyun11 app]# pwd

/opt/app

[root@meiyun11 app]# ls -l
total 11268
drwxr-xr-x.  5 oracle oracle   12288 May 27  2020 openssh-8.3p1
-rw-r--r--.  1 root   root   1706358 Dec 14 16:52 openssh-8.3p1.tar.gz
drwxrwxr-x. 18 root   root      4096 Dec  8 21:20 openssl-1.1.1i
-rw-r--r--.  1 root   root   9808346 Dec 14 16:52 openssl-1.1.1i.tar.gz
现在是系统默认的版本,等会升级完毕对比下

[root@meiyun11 app]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

 备份下面2个文件或目录(如果存在的话就执行)

[root@meiyun11 ldf]# ll /usr/bin/openssl
-rwxr-xr-x. 1 root root 555288 Aug  9  2019 /usr/bin/openssl
[root@meiyun11 ldf]# mv /usr/bin/openssl /usr/bin/openssl_bak
[root@meiyun11 ldf]# ll /usr/include/openssl
[root@meiyun11 ldf]# mv /usr/include/openssl /usr/include/openssl_bak

 

编译安装新版本的openssl

配置、编译、安装3个命令一起执行

&&符号表示前面的执行成功才会执行后面的

 

[root@meiyun11 app]# cd /opt/app/openssl-1.1.1i
[root@meiyun11 openssl-1.1.1i]# ./config shared && make && make install
 

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


 [root@meiyun11 openssl-1.1.1i]#1037  ln -s /usr/local/ssl/include/openssl     /usr/include/openssl

命令行执行下面2个命令加载新配置

echo "/usr/local/lib64" >> /etc/ld.so.conf

/sbin/ldconfig

 

安装openssh 


上传openssh的tar包并解压

可能文件默认显示uid和gid数组都是1000,这里重新授权下。不授权可能也不影响安装(请自行测试)

[root@meiyun11 openssh-8.3p1]# chown -R root.root /opt/app/openssh-8.3p1

 命令行删除原先ssh的配置文件和目录

然后配置、编译、安装

注意下面编译安装的命令是一行,请把第一行末尾的 \ 去掉,然后在文本里弄成一行之后放命令行执行

rm -rf /etc/ssh/*
./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/include/openssl --with-ssl-dir=/usr/local/bin   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

修改配置文件最终为如下内容,其他的不要动

[root@meiyun11 openssh-8.3p1]# grep "^PermitRootLogin"  /etc/ssh/sshd_config
PermitRootLogin yes
[root@meiyun11 openssh-8.3p1]# grep  "UseDNS"  /etc/ssh/sshd_config
#UseDNS no
UseDNS no

 

配置crt或其他putty工具连接算法(不配置可能出现工具连接失败或其他机器ssh登录失败)
 

注意:有些堡垒机可能设置了10022端口的链接,需要修改配置

/etc/ssh/sshd_config加上Port 10022否则连接失败

 从原先的解压的包中拷贝一些文件到目标位置(如果目标目录存在就覆盖)

(可能下面的ssh.pam文件都没用到,因为sshd_config配置文件貌似没使用它,请自行测试。我这边是拷贝了)

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

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
 

 

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

 mv  /usr/lib/systemd/system/sshd.service  /data/

设置sshd服务开机启动

[root@meiyun11 openssh-8.3p1]# chkconfig sshd on
Note: Forwarding request to 'systemctl enable sshd.socket'.
Created symlink from /etc/systemd/system/sockets.target.wants/sshd.socket to /usr/lib/systemd/system/sshd.socket.
[root@meiyun11 openssh-8.3p1]# chkconfig

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
 

 

 接下来测试启停服务。都正常

以后管理sshd通过下面方式了

[root@meiyun11 ~]# /etc/init.d/sshd restart
Restarting sshd (via systemctl):                           [  OK  ]
[root@meiyun11 ~]#
 

systemctl方式管理

[root@meiyun11 ~]# systemctl stop sshd
[root@meiyun11 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      4669/sendmail: acce
[root@meiyun11 ~]#
[root@meiyun11 ~]#
[root@meiyun11 ~]# systemctl start sshd
[root@meiyun11 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      9248/sshd: /usr/sbi
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      4669/sendmail: acce
tcp6       0      0 :::22                   :::*                    LISTEN      9248/sshd: /usr/sbi
 

系统重启后能自动启动sshd服务,版本号正确

[root@meiyun11 ~]# openssl version
OpenSSL 1.1.1i  8 Dec 2020
[root@meiyun11 ~]# ssh -V
OpenSSH_8.3p1, OpenSSL 1.1.1i  8 Dec 2020
[root@meiyun11 ~]#
 

 

引用https://www.cnblogs.com/nmap/p/10779658.html

 

遇到问题

安装完openssl时运行报包libssl.so.1.1不存在

解决方法

echo "/usr/local/lib64" >> /etc/ld.so.conf
 

 

2、升级openssh报 PAM headers not found

在编译openssh的时候报如下错

./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/include/openssl --with-ssl-dir=/usr/local/bin   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

configure: error: PAM headers not found
解决方法

yum -y install pam-devel
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值