您的位置 首页 漏洞

OpenSSH 升级

OpenSSH 有漏洞,

截止2024年7月3日,建议升级到当前最新的版本9.8,或后续更高版本。

openssh版本升级实战(修补ssh漏洞) (zhihu.com)

 

1- 先检查版本:

ssh -V

sshd -V

 

1、安装操作系统依赖包:

yum install -y telnet gcc zlib-devel

2、下载最新版openssh和openssl:

https://www.openssh.com/releasenotes.html

下载:

https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz

 

举例最新为:OpenSSH9.8

2)、由于openssh依赖openssl,所以需要安装新版openssl,从OpenSSH9.4p1开始要求openssl>=1.1.1版本

不要下载 3的版本, 有问题,可以下载1.1.1w

openssl下载网址



https://openssl-library.org/source/old/1.1.1/index.html

举例最新:openssl-3.3.2 版本

 

3)、上传下载的安装包:openssl-1.1.1w.tar.gz和openssh-9.5p1.tar.gz

openssl version

 

tar -xzvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
mkdir -p /usr/openssh/openssl1.1.1w
./config --prefix=/usr/openssh/openssl1.1.1w
make
make install
ll /usr/openssh/openssl1.1.1w
cd ..
rm -rf openssl-1.1.1w*

 

 

 

2)、修改配置文件:

编辑/etc/profile配置文件(vi /etc/profile),设置环境变量,在profile文件最后添加如下两行:

export LD_LIBRARY_PATH=/usr/openssh/openssl1.1.1w/lib:$LD_LIBRARY_PATH
export PATH=/usr/openssh/openssh-9.8p1/bin:/usr/openssh/openssh-9.8p1/sbin:/usr/openssh/openssl1.1.1w/bin:$PATH

 

 

4、编译升级openssh-9.8p1

1)、进入到openssh-9.8p1.tar.gz文件所在的目录,执行编译安装命令:

tar  xf  openssh-9.8p1.tar.gz

cd openssh-9.8p1/

mkdir -p /usr/openssh/openssh-9.8p1/

./configure --prefix=/usr/openssh/openssh-9.8p1 --with-ssl-dir=/usr/openssh/openssl1.1.1w
make && make install

 

2)、修改配置文件:

 vi /usr/openssh/openssh-9.8p1/etc/sshd_config 

#允许root登录,默认值prohibit-password表示root用户只能通过公私钥的方式登录,不能以密码的方式登录

PermitRootLogin yes      

3)、创建sshd服务自启动文件:

vi /usr/lib/systemd/system/sshd9.service
[Unit]
Description=OpenSSH server daemon
After=network.target

[Service]
Type=simple
Environment=LD_LIBRARY_PATH=/usr/openssh/openssl1.1.1w/lib
ExecStart=/usr/openssh/openssh-9.8p1/sbin/sshd -D -f /usr/openssh/openssh-9.8p1etc/sshd_config
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

4)、停用原sshd服务,并备份相关文件

systemctl stop sshd.service
systemctl disable sshd.service

备份文件:

mkdir /home/ssh-old-bak
mv /etc/ssh /home/ssh-old-bak/
mv /usr/sbin/sshd /home/ssh-old-bak/
mv /usr/lib/systemd/system/sshd-keygen.service /home/ssh-old-bak/
mv /usr/lib/systemd/system/sshd.service /home/ssh-old-bak/
mv /usr/lib/systemd/system/sshd@.service /home/ssh-old-bak/
mv /usr/lib/systemd/system/sshd.socket /home/ssh-old-bak/

5)、启动新的sshd服务:

systemctl daemon-reload
systemctl start sshd9.service
systemctl status sshd9.service
systemctl enable sshd9.service

 

5、测试验证

重新连接一个新的窗口来测试新sshd是否可以正常连接,并测试版本号,最后重启服务器测试是否可以重启成功:

sshd -V

ssh -V

 

注意:升级完openssh后,有一些比较老的远程连接工具可能就无法连接上了(由于密钥等问题),例如secureCRT7等,报错例如“Key exchange failed”

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章