• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    linux环境openssl、openssh升级流程

    发布者: 竹韵9933 | 发布时间: 2025-8-14 23:47| 查看数: 22| 评论数: 0|帖子模式

    linux常因openssl、openssh漏洞进行升级。
    本文以ubuntu22.04为例,对openssl、openssh进行升级。

    一.升级openssl


    1.官网下载最新版openssl
    1. wget https://www.openssl.org/source/openssl-3.0.15.tar.gz
    复制代码
    如果因网络原因下载不动,可以直接访问官网,下载最新版本:
    https://www.openssl.org/source/
    1. root@localhost:~# wget https://www.openssl.org/source/openssl-3.0.15.tar.gz
    2. --2024-07-19 07:31:28--  https://www.openssl.org/source/openssl-3.0.15.tar.gz
    3. Resolving www.openssl.org (www.openssl.org)... 34.36.58.177, 2600:1901:0:1812::
    4. Connecting to www.openssl.org (www.openssl.org)|34.36.58.177|:443... connected.
    5. HTTP request sent, awaiting response... 301 Moved Permanently
    6. Location: https://github.com:443/openssl/openssl/releases/download/openssl-3.0.15/openssl-3.0.15.tar.gz [following]
    7. --2024-07-19 07:31:29--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/7634677/6ac36897-7f0a-4dc5-8d1c-3d8b0eab4f5d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240719%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240719T073129Z&X-Amz-Expires=300&X-Amz-Signature=658f52e12bd883cbda4f7abcbac2508a5642bccc70baf8d159b4e39a31623702&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=7634677&response-content-disposition=attachment%3B%20filename%3Dopenssl-3.0.15.tar.gz&response-content-type=application%2Foctet-stream
    8. Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133
    9. Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
    10. HTTP request sent, awaiting response... 200 OK
    11. Length: 15305497 (15M) [application/octet-stream]
    12. Saving to: ‘openssl-3.0.15.tar.gz'

    13. openssl-3.0.15.tar.gz                  100%[===========================================================================>]  14.60M  81.0KB/s    in 4m 17s  

    14. 2024-07-19 07:35:48 (58.1 KB/s) - ‘openssl-3.0.15.tar.gz' saved [15305497/15305497]
    复制代码
    2.安装编译环境
    1. apt-get install -y build-essential
    复制代码
    1. root@localhost:/opt/openssl-3.0.15# apt-get install -y build-essential
    2. Reading package lists... Done
    3. Building dependency tree... Done
    4. Reading state information... Done
    5. The following additional packages will be installed:
    6.   bzip2 cpp cpp-11 dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-11 gcc gcc-11 gcc-11-base libalgorithm-diff-perl
    7.   libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libdeflate0
    8.   libdpkg-perl libfakeroot libfile-fcntllock-perl libfontconfig1 libgcc-11-dev libgd3 libgomp1 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 liblsan0
    9.   libmpc3 libnsl-dev libquadmath0 libstdc++-11-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libxpm4 linux-libc-dev lto-disabled-list make
    10.   manpages-dev rpcsvc-proto
    11. Suggested packages:
    12.   bzip2-doc cpp-doc gcc-11-locales debian-keyring g++-multilib g++-11-multilib gcc-11-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc
    13.   gcc-11-multilib glibc-doc bzr libgd-tools libstdc++-11-doc make-doc
    复制代码
    如果系统为CentOS,则执行
    1. yum install perl-IPC-Cmd perl-Data-Dumper gcc gcc-c++ perl perl-devel -y
    复制代码
    3.下载后解压安装
    1. tar -xf openssl-3.0.15.tar.gz -C /opt/
    复制代码
    进入目录
    1. cd /opt/openssl-3.0.15
    复制代码
    编译配置openssl安装目录
    1. ./config --prefix=/usr/local/openssl
    复制代码
    1. root@localhost:~# tar -xf openssl-3.0.15.tar.gz -C /opt/
    2. root@localhost:~# cd /opt/openssl-3.0.15/
    3. root@localhost:/opt/openssl-3.0.15# ./config --prefix=/usr/local/openssl
    4. Configuring OpenSSL version 3.0.15 for target linux-x86_64
    5. Using os-specific seed configuration
    6. Created configdata.pm
    7. Running configdata.pm
    8. Created Makefile.in
    9. Created Makefile
    10. Created include/openssl/configuration.h

    11. **********************************************************************
    12. ***                                                                ***
    13. ***   OpenSSL has been successfully configured                     ***
    14. ***                                                                ***
    15. ***   If you encounter a problem while building, please open an    ***
    16. ***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
    17. ***   and include the output from the following command:           ***
    18. ***                                                                ***
    19. ***       perl configdata.pm --dump                                ***
    20. ***                                                                ***
    21. ***   (If you are new to OpenSSL, you might want to consult the    ***
    22. ***   'Troubleshooting' section in the INSTALL.md file first)      ***
    23. ***                                                                ***
    24. **********************************************************************
    复制代码
    安装
    1. make && make install
    复制代码
    1. root@localhost:/opt/openssl-3.0.15# make && make install/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/crypto/bn_conf.h.in > include/crypto/bn_conf.h/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/crypto/dso_conf.h.in > include/crypto/dso_conf.h/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/asn1.h.in > include/openssl/asn1.h/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/asn1t.h.in > include/openssl/asn1t.h/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/bio.h.in > include/openssl/bio.h/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/cmp.h.in > include/openssl/cmp.h
    复制代码
    4.备份更新openssl

    备份openssl
    1. mv /usr/bin/openssl /usr/bin/openssl_bak
    复制代码
    复制openssl文件到/usr/bin/下
    1. cp /usr/local/openssl/bin/openssl /usr/bin/
    复制代码
    添加动态链接库数据
    1. echo ‘/usr/local/openssl/lib64/' >> /etc/ld.so.conf
    复制代码
    更新动态链接库
    1. ldconfig
    复制代码
    1. root@localhost:/opt/openssl-3.0.15# mv /usr/bin/openssl /usr/bin/openssl_bak
    2. root@localhost:/opt/openssl-3.0.15# cp /usr/local/openssl/bin/openssl  /usr/bin/
    3. root@localhost:/opt/openssl-3.0.15# echo "/usr/local/openssl/lib64/" >> /etc/ld.so.conf
    4. root@localhost:/opt/openssl-3.0.15# ldconfig
    复制代码
    5.进行验证
    1. openssl version
    复制代码
    1. root@localhost:/usr/local/openssl/lib64# openssl version
    2. OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)
    复制代码
    若出现如下问题
    1. root@localhost:/opt/openssl-3.0.15# openssl version
    2. openssl: /lib/x86_64-linux-gnu/libcrypto.so.3: version `OPENSSL_3.0.9' not found (required by openssl)
    复制代码
    备份libcrypto.so.3文件后,复制安装目录下lib64/libcrypto.so.3到/lib/x86_64-linux-gnu/目录
    1. root@localhost:/opt/openssl-3.0.15# cd /usr/local/openssl/lib64/root@localhost:/usr/local/openssl/lib64# lltotal 16636drwxr-xr-x 5 root root    4096 Jul 19 07:49 ./drwxr-xr-x 7 root root    4096 Jul 19 07:50 ../drwxr-xr-x 2 root root    4096 Jul 19 07:49 engines-3/-rw-r--r-- 1 root root 9541222 Jul 19 07:49 libcrypto.alrwxrwxrwx 1 root root      14 Jul 19 07:49 libcrypto.so -> libcrypto.so.3*-rwxr-xr-x 1 root root 5383824 Jul 19 07:49 libcrypto.so.3*-rw-r--r-- 1 root root 1268762 Jul 19 07:49 libssl.alrwxrwxrwx 1 root root      11 Jul 19 07:49 libssl.so -> libssl.so.3*-rwxr-xr-x 1 root root  813928 Jul 19 07:49 libssl.so.3*drwxr-xr-x 2 root root    4096 Jul 19 07:49 ossl-modules/drwxr-xr-x 2 root root    4096 Jul 19 07:49 pkgconfig/root@localhost:/usr/local/openssl/lib64# mv /lib/x86_64-linux-gnu/libcrypto.so.3 /root/root@localhost:/usr/local/openssl/lib64# cp libcrypto.so.3 /lib/x86_64-linux-gnu/root@localhost:/usr/local/openssl/lib64# openssl version
    2. OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)
    复制代码
    二、升级openssh


    1.下载最新版openssh
    1. wget
    2. https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.9p1.tar.gz
    复制代码
    如因网络原因下载不动,可以直接访问 ,下载最新版本https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable

    2.安装相关依赖
    1. apt-get install -y zlib1g-dev libpam0g-dev
    复制代码
    1. root@localhost:~#  apt-get install -y  zlib1g-dev libpam0g-dev
    2. Reading package lists... Done
    3. Building dependency tree... Done
    4. Reading state information... Done
    5. The following NEW packages will be installed:
    6.   libpam0g-dev zlib1g-dev
    7. 0 upgraded, 2 newly installed, 0 to remove and 67 not upgraded.
    8. Need to get 281 kB of archives.
    9. After this operation, 1,010 kB of additional disk space will be used.
    10. Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libpam0g-dev amd64 1.4.0-11ubuntu2.4 [117 kB]
    11. Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu9.2 [164 kB]
    12. Fetched 281 kB in 2s (142 kB/s)
    复制代码
    系统为CentOS,则执行
    1. yum install zlib-devel pam-devel -y
    复制代码
    3.解压安装
    1. tar xf openssh-9.9p1.tar.gz -C /opt/
    2. cd /opt/openssh-9.9p1
    复制代码
    配置安装目录
    1. ./configure --prefix=/usr/local/openssh
    2. –with-ssl-dir=/usr/local/openssl --sysconfdir=/etc/ssh --with-pam --with-gssapi --with-rsa --with-rhosts-allowed --with-zlib --with-md5-passwords
    复制代码
    编译安装
    1. make && make install
    复制代码
    4.查看目录版本
    1. /usr/local/openssh/bin/ssh -V
    复制代码
    1. root@localhost:/usr/local/openssh# ./bin/ssh -V
    2. OpenSSH_9.9p1, OpenSSL 3.0.15 3 Sep 2024
    复制代码
    5.备份替换相关文件
    1. mv /usr/sbin/sshd /usr/sbin/sshd_bak
    2. mv /usr/bin/ssh /usr/bin/ssh_bak
    3. mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen_bak
    复制代码
    1. cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
    2. cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh
    3. cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
    复制代码
    6.重启ssh服务
    1. systemctl restart sshd
    复制代码
    1. root@localhost:/usr/local/openssh# systemctl restart sshd.service
    2. root@localhost:/usr/local/openssh# ssh -V
    3. OpenSSH_9.9p1, OpenSSL 3.0.15 3 Sep 2024
    复制代码
    执行ssh服务状态查询命令
    1. systemctl status sshd.service
    复制代码
    查看发现文件的权限设置过于宽松
    1. Permissions 0640 for'/etc/ssh/*****.key' are too open.
    复制代码
    执行chmod -R 600 /etc/ssh限制权限后重启ssh服务
    1. systemctl restart sshd
    复制代码
    总结

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    浏览过的版块

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表