Centos7升级openssl和openssh最新版

[复制链接]
发表于 2025-10-20 21:03:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
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的版本信息

  1. # 查看CentOS系统版本信息
  2. cat /etc/redhat-release
  3. # 查看openssl版本信息
  4. openssl version
  5. # 查看openssh的版本信息
  6. ssh -V
复制代码

3、安装依靠

  1. yum -y install gcc pam-devel zlib-devel openssl-devel net-tools
  2. yum install -y perl-IPC-Cmd perl-Data-Dumper
复制代码
4、安装openssl-3.4.1版本

(1)解压openssl-3.4.1压缩包

  1. tar zxvf openssl-3.4.1.tar.gz -C /usr/local/
  2. cd /usr/local/openssl-3.4.1/
  3. mkdir /opt/openssl
复制代码
(2)编译安装openssl-3.4.1

  1. ./config --prefix=/opt/openssl
  2. make -j4 && make install   ###-j后面的数字为你的内核数
复制代码
(3)更新lib文件

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

(4)更新bin文件

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

5、编译安装openssh9.9p2

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

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

  1. # 配置编译和安装过程,"--prefix=" 配置安装目录,"--sysconfdir=" 配置文件路径,"--with-ssl-dir=" openssl的安装路径
  2. ./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
  3. chmod 600 /etc/ssh/ssh_host_*_key
  4. chown root:root /etc/ssh/ssh_host_*_key
  5. make -j4 && make install
复制代码
(3)复制并修改启动sshd.init脚本

  1. # 从源码目录下复制sshd.init到/etc/init.d/
  2. cp /usr/local/openssh-9.9p2/contrib/redhat/sshd.init /etc/init.d/
  3. ## 查看并修改SSHD的新路径,将新的openssh安装路径更新
  4. cat /etc/init.d/sshd.init | grep SSHD
  5. sed -i "s/SSHD=\/usr\/sbin\/sshd/SSHD=\/usr\/local\/openssh\/sbin\/sshd/g" /etc/init.d/sshd.init
  6. cat /etc/init.d/sshd.init | grep SSHD
  7. ## 查看并修改ssh-keygen的新路径,将新的ssh-keygen安装路径更新
  8. cat -n /etc/init.d/sshd.init | grep ssh-keygen
  9. sed -i "s#/usr/bin/ssh-keygen -A#/usr/local/openssh/bin/ssh-keygen -A#g" /etc/init.d/sshd.init
  10. cat -n /etc/init.d/sshd.init | grep ssh-keygen
复制代码


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

  1. # 开启允许X11转发
  2. echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
  3. # 开启允许密码验证
  4. echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
复制代码
(5)启动openssh,并设置开机启动

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

(6)测试openssh毗连

使用ssh协议毗连centos7,查抄openssh9.9p2服务
重启体系后ssh协议登录centos7,查抄openssh9.9p2自动启动
6、查抄体系、openssl和openssh的版本信息


回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表