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

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - likingzi

数据库IO性能优化思考 RAID10和RAID5性能对比测试 迁移MySQL数据到Oracle实践记录 瀚高数据库不同版本对实例级用户的支持情况 使用benchmarksql测试数据库处理能力 【翻译】凝视深渊:千核并发控制的评估 NFS使用TrueNAS SCALE的好处 linux 手动释放内存 linux8安装oracle 11g遇到的问题记录 ARM架构鲲鹏主机BClinux离线安装docker步骤 ORA-01658创建表或索引报错分析 MySQL PXC 集群死锁分析案例 记录一下oracle 19c的集群节点移除、新增操作 MySQL PXC集群多个节点同时大量并发update同一行 MongoDB集群同步 【最佳实践】MySQL数据库迁移到PXC集群 MySQL PXC集群配置IPv6 【实操记录】MySQL主从配置 【实操记录】MySQL二进制安装包部署 MongoDB分片+副本集高可用集群的启停步骤
BigCloud Enterprise Linux 8和Rocky Linux 8升级OpenSSH步骤
likingzi · 2025-02-26 · via 博客园 - likingzi

之前陆续整理过好几次升级openssh的文章,随着时间的推移,也该更新了,正好当下这个升级需求比较多,尤其是安全扫描时往往大部分高危漏洞来自于低版本的openssh,升级后可以解决大部分漏洞。

根据最近的实践,以下操作适应于如下linux版本:
BigCloud Enterprise Linux 8.2/8.6
Rocky Linux 8.10
bclinux/bc-linux/bc linux

一、配置telnet服务、gcc编译器

目的:确保不会因为升级ssh失误导致无法远程登陆主机
■ 确认telnet服务是否已经安装
yum info telnet*
■ 如果没有安装telnet-server
yum install telnet-server -y
■ linux7
安装了telnet-server后,可直接启动telnet-server,不必配置xinetd
systemctl start telnet.socket
■ 此时测试能否远程telnet登陆服务器,确认telnet服务生效后,就可以进行下一步
■ 安装openssh需gcc编译器,确认是否安装
yum info gcc
如没有安装,则安装:
yum install gcc

二、安装新版本zlib【可选】

一般linux8版本的zlib库版本不需要升级

三、安装新版本openssl【可选】

一般linux8版本的openssl库版本不需要升级

四、备份老版本openssh

tar cvf /root/sshd20250210.tar /usr/lib/systemd/system/sshd*
mv /usr/lib/systemd/system/sshd-keygen.target{,.ori}
mv /usr/lib/systemd/system/sshd.service{,.ori}
mv /usr/lib/systemd/system/sshd.socket{,.ori}
mv /usr/lib/systemd/system/sshd-keygen@.service{,.ori}
mv /usr/lib/systemd/system/sshd@.service{,.ori}
mv /etc/ssh{,.ori}

五、安装新版本openssh

1、官网下载最新版本源码

【版本9.9p1】
www.openssh.com
最新版本国内镜像地址见下一步。

2、配置、编译、安装

wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.9p1.tar.gz
tar xvfz openssh-*.tar.gz
cd openssh-9.9p1
./configure --prefix=/usr/local --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords
此时可能会报错:
checking for openssl... /usr/bin/openssl
configure: error: *** working libcrypto not found, check config.log
则需安装 openssl-devel:yum install -y openssl-devel
或者报错:找不到pam文件头,则安装pam-devel包即可:
yum install pam-devel -y
make
make install

注:prefix指定安装路径/usr/local;sysconfdir指定配置文件路径;with-zlib指定新版本zlib路径;with-pam指定启用pam支持;with-ssl-dir指定openssl路径

六、配置新的sshd系统服务

1、生成新的服务配置文件,3个

cat > /usr/lib/systemd/system/sshd-keygen.service << EOF
[Unit]
Description=OpenSSH Server Key Generation
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
ConditionPathExists=|!/etc/ssh/ssh_host_dsa_key
PartOf=sshd.service sshd.socket

[Service]
ExecStart=/usr/local/bin/ssh-keygen
Type=oneshot
RemainAfterExit=yes
EOF

---

cat > /usr/lib/systemd/system/sshd.service << EOF
[Unit]
Description=OpenSSH server daemon
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/local/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
EOF

---

cat > /usr/lib/systemd/system/sshd.socket << EOF
[Unit]
Description=OpenSSH Server Socket
Conflicts=sshd.service

[Socket]
ListenStream=22
Accept=yes

[Install]
WantedBy=sockets.target
EOF

将3个服务配置文件属性改为644
chmod 644 /usr/lib/systemd/system/sshd*

2、修改sshd配置

【make install时自动生成新sshd配置文件】
参考原sshd配置/etc/ssh/sshd_config,修改新sshd配置
如下命令行操作,确认端口号,打开PAM支持:

sed -i "s/#UsePAM no/UsePAM yes/g" /etc/ssh/sshd_config
打开root登录:
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config

3、启动sshd服务

systemctl daemon-reload
systemctl restart sshd
systemctl enable sshd

4、其他修改

■ 确认升级后的版本
telnet localhost 22

■ 验证可以远程ssh登陆以后,可以关闭telnet服务
systemctl stop telnet.socket
systemctl disable telnet.socket
如果不能远程登录,一般是因为防火墙和SELINUX设置问题,可以关闭防火墙和关闭SELINUX:
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
永久关闭selinux,修改/etc/selinux/config 文件:
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

■ ssh客户端程序更新
mv /usr/bin/ssh /usr/bin/ssh.old
ln -s /usr/local/bin/ssh /usr/bin/ssh