升级openSSH

该博客介绍了在Red Hat Enterprise Linux Server 7.4系统上安装OpenSSH的详细步骤。包括查看系统和SSL版本,更新zlib、安装pam - devel和OpenSSL,备份、卸载并重新安装OpenSSH,还提及安装后环境配置、启动服务及验证升级结果,同时提醒关闭防火墙和SELinux。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、当前系统版本

 [root@localhost ~]# cat /etc/redhat-release  

Red Hat Enterprise Linux Server release 7.4 (Maipo)

[root@localhost ~]# uname -m

x86_64

[root@localhost ~]# uname -r

3.10.0-693.el7.x86_64

2、SSL版本信息

 [root@localhost ~]# openssl version

OpenSSL 1.0.2k-fips  26 Jan 2017

3、更新zlib

1、下载最新版本 Zlib
Zlib 官方网站:http://www.zlib.net/
2、编译安装 Zlib
# tar xzvf zlib-1.2.11.tar.gz

# cd zlib-1.2.11
# ./configure --prefix=/usr/local/zlib
# make
# make install
这样,就把 zlib 编译安装在
/usr/local/zlib 中了。

4、安装pam-devel

1.下载最新版本pam-devel

pam-devel官方下载网站: https://pkgs.org/download/pam-devel

2.rpm安装pam-devel

# rpm -ivh pam-devel-1.1.8-18.el7.x86_64.rpm

这样就安装好了

5、安装 OpenSSL
1、下载最新版本openssl以及openssl-fips
OpenSSL 的官方网站:http://www.openssl.org
2、编译安装openssl-fips

[root@localhost ~]# tar -xzvf openssl-fips-2.0.16.tar.gz

[root@localhost ~]# cd openssl-fips-2.0.16

[root@localhost openssl-fips-2.0.16]# ./config

[root@localhost openssl-fips-2.0.16]# make

[root@localhost openssl-fips-2.0.16]# make install

默认安装到/usr/local/ssl/fips-2.0

3、编译安装openssl 
[root@localhost ~]# tar -xzvf openssl-1.0.2m.tar.gz
[root@localhost openssl-1.0.2m]# cd openssl-1.0.2m
[root@localhost openssl-1.0.2m]# ./config --prefix=/usr/ --shared zlib 
 

或者

[root@localhost openssl-1.0.2m]# ./config --prefix=/usr/ --shared fips

(必须加上--shared,否则编译时会找不到新安装的openssl的库而报错)
[root@localhost openssl-1.0.2m]# make
[root@localhost openssl-1.0.2m]# make test 

(这一步很重要哦!是进行 SSL加密协议的完整测试,如果出现错误就要一定先找出哪里的原因,否则一味继续可能导致最终 SSH 不能使用,后果很严重哦!)
[root@localhost openssl-1.0.2m]# make install

或者安装的升级方式如下所示:

# pwd  

/root/tools  

# ls  

openssl-1.0.1g.tar.gz  

# tar xf openssl-1.0.1g.tar.gz   

# cd openssl-1.0.1g  

# ./config shared zlib  

# make  

# make install  

# cd ..  

# mv /usr/bin/openssl /usr/bin/openssl.ori              # 将之前的备份  

# mv /usr/include/openssl /usr/include/openssl.ori  

# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl     # 软链接  

# ln -s /usr/local/ssl/include/openssl /usr/include/openssl  

# cp /etc/ld.so.conf /etc/ld.so.conf.ori                # 操作前备份【这样如果出现错误,可以及时还原】  

# echo “/usr/local/ssl/lib” >> /etc/ld.so.conf  

# ldconfig -v  

其中 /etc/ld.so.conf 修改后的信息【使用vim修改】

[zhang@zhang ~] $ cat /etc/ld.so.conf  

include ld.so.conf.d/*.conf  

#  Update openssl from OpenSSL 1.0.1e-fips  To   OpenSSL 1.0.1g  

/usr/local/ssl/lib  

4、查看是否升级成功

[root@localhost openssl-1.0.2m]# openssl version

OpenSSL 1.0.2m  2 Nov 2017       # 升级成功  

6、安装 OpenSSH

1、下载最新软件包源码

官方下载地址http://www.openssh.com/portable.html#http

2、备份当前openssh

[root@localhost openssl-1.0.2m]# mv /etc/ssh /etc/ssh.old

3、卸载当前openssh

[root@localhost openssl-1.0.2m]# rpm -qa | grep openssh

openssh-clients-7.4p1-11.el7.x86_64

openssh-server-7.4p1-11.el7.x86_64

openssh-7.4p1-11.el7.x86_64

[root@localhost openssl-1.0.2m]# rpm -e --nodeps openssh-clients-7.4p1-11.el7.x86_64

[root@localhost openssl-1.0.2m]# rpm -e --nodeps openssh-server-7.4p1-11.el7.x86_64

[root@localhost openssl-1.0.2m]# rpm -e --nodeps openssh-7.4p1-11.el7.x86_64

[root@localhost openssl-1.0.2m]# rpm -qa | grep openssh

4、安装openssh

[root@localhost ~]# tar -xzvf openssh-7.6p1.tar.gz

[root@localhost ~]# cd openssh-7.6p1

编译(同时兼容ssh1协议)

[root@localhost openssh-7.6p1]# ./configure --prefix=/usr  --sysconfdir=/etc/ssh  --with-md5-passwords  --with-pam  --with-zlib --with-ssh1

[root@localhost openssh-7.6p1]#make

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

5、安装后环境配置

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

[root@localhost redhat]# chmod +x /etc/init.d/sshd

[root@localhost redhat]# chkconfig --add sshd

进入/etc/ssh目录修改sshd_config文件,添加PermitRootLogin yes到文件末尾

cd /etc/ssh

修改文件

vi sshd_config

添加PermitRootLogin yes到文件末尾

保存,退出

6、启动ssh服务

service sshd start

7、验证是否升级成功

 [root@localhost ssh]# ssh -V

OpenSSH_7.6p1, OpenSSL 1.0.2m  2 Nov 2017 (升级成功)

 

注意:记得关闭防火墙systemctl stop firewalld,记得关闭SELinux:

1、临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

                              ##setenforce 1 设置SELinux 成为enforcing模式

2、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

### 如何升级 OpenSSH 至最新版本 #### 准备工作 为了确保安全性和兼容性,在开始之前应备份重要数据以及现有配置文件。由于OpenSSH依赖于SSL库,如果打算更新至更高版本的OpenSSH,则可能也需要考虑编译一个新的独立版本的OpenSSL来支持它[^3]。 #### 下载源码包 前往官方网站获取最新的`*.tar.gz`格式的安装包。例如,可以从以下链接下载指定版本: ```bash wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz ``` #### 编译前准备 解压下载好的压缩包,并切换到对应的目录下进行后续操作。在此之前,建议先确认系统已安装必要的构建工具链(如gcc、make等),可以通过yum或其他方式安装这些开发环境组件。 #### 配置与编译 创建一个自定义路径用于存放新编译后的程序及其关联文件夹结构;接着运行configure脚本来设定编译参数,这里可以指定使用刚才提到的新版OpenSSL的位置作为依赖项之一。完成上述设置之后便能调用make指令启动实际编译过程。 ```bash ./configure --prefix=/usr/local/openssh --with-ssl-dir=/path/to/new_openssl make ``` #### 替换原有服务 停止正在运行的服务实例,移除旧版本的相关rpm包(注意这一步骤可能会因不同Linux发行版而有所差异)。随后把刚刚生成的目标文件复制到相应位置覆盖掉原有的可执行文件。最后重启sshd守护进程使更改生效。 ```bash service sshd stop yum remove openssh* cp sshd /usr/sbin/sshd service sshd start ``` #### 版本验证 通过命令行检查当前使用的OpenSSH版本是否已经成功更改为预期目标版本。 ```bash ssh -V ``` 此时应当显示类似于 `OpenSSH_8.5p1, ...` 的输出结果表示升级顺利完成[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值