Centos7升级openssl和openssh最新版

1、事前准备

下载openssl3.4.1和openssh9.9p2压缩包上传到服务器

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

Release OpenSSL 3.4.1 · openssl/openssl · GitHub

2、查看centos7、ssh以及openssl的版本信息

复制代码
# 查看CentOS系统版本信息
cat /etc/redhat-release
# 查看openssl版本信息
openssl version
# 查看openssh的版本信息
ssh -V

3、安装依赖

复制代码
yum -y install gcc pam-devel zlib-devel openssl-devel net-tools
yum install -y perl-IPC-Cmd perl-Data-Dumper

4、安装openssl-3.4.1版本

(1)解压openssl-3.4.1压缩包

复制代码
tar zxvf openssl-3.4.1.tar.gz -C /usr/local/
cd /usr/local/openssl-3.4.1/
mkdir /opt/openssl

(2)编译安装openssl-3.4.1

复制代码
./config --prefix=/opt/openssl
make -j4 && make install   ###-j后面的数字为你的内核数

(3)更新lib文件

复制代码
ldd /opt/openssl/bin/openssl
echo "/opt/openssl/lib" >> /etc/ld.so.conf
echo "/opt/openssl/lib64" >> /etc/ld.so.conf
echo "/usr/local/openssl-3.4.1" >> /etc/ld.so.conf
ldconfig -v
ldd /opt/openssl/bin/openssl

(4)更新bin文件

复制代码
# 查看旧版本的openssl命令路径
which openssl
# 重命名为openssl.old
mv /usr/bin/openssl /usr/bin/openssl.old   #重命名openssl文件
# 使用软连接的方式更新openssl命令
ln -s /opt/openssl/bin/openssl /usr//bin/openssl
# openssl命令查看版本呢
openssl version

5、编译安装openssh9.9p2

(1)解压缩openssh9.9p2压缩包

复制代码
# 卸载openssh的rpm包
for i in $(rpm -qa | grep openssh);do rpm -e $i --nodeps;done
# 解压缩openssh9.7p1包到目标目录
cd ~
tar zvxf openssh-9.9p2.tar.gz -C /usr/local/
# 进入openssh9.7p1的源码目录
cd /usr/local/openssh-9.9p2/
# 安装前查看一下安装文件INSTALL(建议看一下)
more INSTALL

(2)编译安装openssh9.9p2

复制代码
# 配置编译和安装过程,"--prefix=" 配置安装目录,"--sysconfdir=" 配置文件路径,"--with-ssl-dir=" openssl的安装路径
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/opt/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening

chmod 600 /etc/ssh/ssh_host_*_key
chown root:root /etc/ssh/ssh_host_*_key

make -j4 && make install

(3)复制并修改启动sshd.init脚本

复制代码
# 从源码目录下复制sshd.init到/etc/init.d/
cp /usr/local/openssh-9.9p2/contrib/redhat/sshd.init /etc/init.d/

## 查看并修改SSHD的新路径,将新的openssh安装路径更新
cat /etc/init.d/sshd.init | grep SSHD
sed -i "s/SSHD=\/usr\/sbin\/sshd/SSHD=\/usr\/local\/openssh\/sbin\/sshd/g" /etc/init.d/sshd.init
cat /etc/init.d/sshd.init | grep SSHD

## 查看并修改ssh-keygen的新路径,将新的ssh-keygen安装路径更新
cat -n /etc/init.d/sshd.init | grep ssh-keygen
sed -i "s#/usr/bin/ssh-keygen -A#/usr/local/openssh/bin/ssh-keygen -A#g" /etc/init.d/sshd.init
cat -n /etc/init.d/sshd.init | grep ssh-keygen

(4)修改配置文件(sshd_config)

复制代码
# 开启允许X11转发
echo 'X11Forwarding yes' >> /etc/ssh/sshd_config 
# 开启允许密码验证
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config 

(5)启动openssh,并设置开机启动

复制代码
# 复制ssh的相关命令
cp -arp /usr/local/openssh/bin/* /usr/bin/
# 启动sshd服务
/etc/init.d/sshd.init start
# 查看版本
ssh -V
# 添加开机启动
chmod +x /etc/rc.d/rc.local
echo "/etc/init.d/sshd.init start" >> /etc/rc.d/rc.local  
systemctl enable --now rc-local

(6)测试openssh连接

使用ssh协议连接centos7,检查openssh9.9p2服务

重启系统后ssh协议登录centos7,检查openssh9.9p2自动启动

**6、**检查系统、openssl和openssh的版本信息

相关推荐
木下~learning4 分钟前
零基础Git入门:Linux+Gitee实战指南
linux·git·gitee·github·虚拟机·版本控制·ubunt
不愿透露姓名的大鹏4 分钟前
MySQL Binlog配置优化全攻略
运维·服务器·数据库·mysql·adb
●VON8 分钟前
本地大模型部署实录:从Docker环境搭建到Open WebUI公网访问
运维·docker·容器·大模型
IMPYLH15 分钟前
Linux 的 mkdir 命令
linux·运维·服务器·bash
yy_xzz18 分钟前
【Linux开发】多线程并发服务器(网络编程+多线程+线程同步实现的聊天服务器和客户端)
linux·服务器·网络
网络研究员23 分钟前
Facebook无法向他人发送消息?2026原因解析与解决思路
运维·服务器
电子阿板23 分钟前
ubuntu虚拟机查看tusb8041扩展坞及U盘的设置方法
linux·运维·ubuntu
迷路爸爸18026 分钟前
Docker 入门学习笔记 07:用一个多服务案例真正理解 Docker Compose
运维·笔记·学习·spring cloud·docker·容器·eureka
孤影过客26 分钟前
Linux下的PostgreSQL集群演进指南
linux·运维·postgresql
Arvin62730 分钟前
Jenkins 任务执行完成后会kill掉的衍生进程
运维·servlet·jenkins