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

推荐订阅源

T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
V
V2EX
GbyAI
GbyAI
量子位
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
O
OpenAI News
N
News and Events Feed by Topic
博客园 - Franky
爱范儿
爱范儿
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
Last Week in AI
Last Week in AI
罗磊的独立博客
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
J
Java Code Geeks
I
Intezer

博客园 - 渺晓

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文件去批量执行,本文只是记录单个的方法和原理,不建议在不了解原理前就直接使用网上的一键执行语句