惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
博客园 - 叶小钗
Jina AI
Jina AI
罗磊的独立博客
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
博客园 - Franky
AWS News Blog
AWS News Blog
S
Schneier on Security
K
Kaspersky official blog
I
Intezer
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
L
LINUX DO - 热门话题
GbyAI
GbyAI
月光博客
月光博客
C
Cisco Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
P
Privacy International News Feed
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
P
Proofpoint News Feed
T
Tor Project blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
S
Security Affairs
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog

博客园 - 渺晓

2025年终总结2026展望 2024年终总结 2023年终总结 ELK自动清理索引 docker+docker-compose部署rocketmq集群遇到的大坑 docker-compose部署rocketmq集群 centos7安装docker compose k8s部署jar包心得 kubernetes集群搭建2023 kubepi加入集群,生成token Windows11 Centos7 SSH Server配置 RSA公钥登录 免密登录 CentOS7 安装ElasticSearch8.9+Kibana8.9 windows服务器nginx和iis端口冲突问题 Linux(Centos7.6) 逻辑卷扩容 磁盘扩容 LVM扩容 LVM创建 逻辑卷挂载 2022年终总结 python pdf转图片 Windows搭建Mysql8 java基础 idea maven 私库 Window10启动Consul后页面UI卡住
centos7.9 升级openssh(9.7p1)
渺晓 · 2024-05-30 · via 博客园 - 渺晓

参考自:https://blog.csdn.net/morecccc/article/details/134758892

原文亲测有效,本文用于备份和记录心得

注意事项:

①先安装telnet,防止ssh升级失败,连不上服务器的情况(但是需要拥有root密码,才能使用su root,不然这一步可以省略)

②下载想要的版本的包

cd /usr/local/src/
wget https://www.openssl.org/source/openssl-3.2.1.tar.gz
wget https://zlib.net/current/zlib.tar.gz
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz

③解压安装zlib

cd /usr/local/src/
tar zxvf zlib.tar.gz
cd zlib-1.3.1
yum install gcc gcc-c++ make -y
./configure --prefix=/usr/local/zlib
make && make install

④升级ssl
cd /usr/local/src/
tar zxvf openssl-3.2.1.tar.gz
cd openssl-3.2.1
yum install -y perl-CPAN perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
./config --prefix=/usr/local/ssl --shared
make && make install

④①备份ssl,以防未知情况导致升级失败,可以回到升级前的版本(这里特别注意该备份语句只能执行一次,不然会覆盖备份文件导致本次备份失败)

mv -f /usr/bin/openssl /usr/bin/openssl.bak

④②路径写入etc/ld.so.conf(这里也有坑,需要根据服务器环境来配置,第一次按照原文用/usr/local/ssl/lib并不能成功)

[root@localhost ~]# whereis openssl
openssl: /usr/bin/openssl /usr/bin/openssl.bak /usr/lib64/openssl /usr/include/openssl

我的服务只有64位的路径,所以用了下面的路径

echo '/usr/local/ssl/lib64' >> /etc/ld.so.conf
④③建立软连接
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl

④④检查配置问题(个人猜测)
ldconfig -v

④⑤查看ssl版本是否为新的版本
openssl version -a

⑤升级sshd

⑤①备份ssh相关文件

cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp -p /usr/sbin/sshd /usr/sbin/sshd.bak
cp -p /usr/bin/ssh /usr/bin/ssh.bak
cp -p /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -p /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak

⑤②停止sshd服务,并备份ssh文件夹

systemctl stop sshd
cp -r /etc/ssh /etc/ssh.old

⑤③卸载ssh,注意全部卸载干净
rpm -qa | grep openssh
yum remove openssh-7.4p1-23.el7_9.x86_64
rpm -qa | grep openssh

⑤④升级ssh
cd /usr/local/src/
tar zxvf openssh-9.7p1.tar.gz
cd openssh-9.7p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install

⑤⑤添加相关配置
echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config

⑤⑥将编译安装的新配置复制到原目录中

cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub

⑤⑦复制启动脚本,并添加启动权限
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd

⑤⑧重启ssh,并查看状态

systemctl restart sshd
systemctl status sshd

⑤⑨重新加载ssh配置

systemctl daemon-reload

⑤⑩查看ssh版本是否为新版本
ssh -V

如果是很多台服务器可以自己搞成sh文件去批量执行,本文只是记录单个的方法和原理,不建议在不了解原理前就直接使用网上的一键执行语句