Kylin Server V10下OpenSSH安全漏洞离线修复脚本

本文详细介绍了如何在Linux系统中安装OpenSSH9.7p1,包括查看系统信息、SSH配置、目录操作、编辑setup.sh脚本进行安装、更新脚本update.sh以及管理sshd.service和sshd.conf文件。最后展示了更新后OpenSSH的版本信息。
摘要由CSDN通过智能技术生成

1.查看操作系统信息

[root@localhost ~]# cat /etc/.kyinfo

2.查看SSH信息

[root@localhost ~]# ssh -V

OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020

3.查看目录结构

[root@localhost openssh]#ls

openssh.tar.gz是openssh二进制压缩包

4. 编辑setup.sh

[root@localhost openssh]#vi setup.sh

###########################################################################################
#  @programe  : openssh_setup.sh 
#  @version   : 0.0.1                                                       
#  @function@ : 
#  @campany   : 
#  @dep.      :                                         
#  @writer    : Liu Cheng Ji                                              
#  @date      : 2024-02-04                                                
##########################################################################################
#!/bin/bash

tar -zxvf openssh.tar.gz -C /usr/local/

openssh_version=`ssh -V 2>&1 | awk -F "," '{print $1}'`
openssh_version_num=${openssh_version:8: 3}

if [ -f /lib/systemd/system/sshd.service ];then
	mv /lib/systemd/system/sshd.service /lib/systemd/system/sshd_$openssh_version_num.service
	cp ./config/sshd.service /lib/systemd/system/
fi

chown root:root /lib/systemd/system/sshd.service
chmod 0644 /lib/systemd/system/sshd.service

cp ./config/sshd.conf /usr/lib/tmpfiles.d/
chown root:root /usr/lib/tmpfiles.d/sshd.conf
chmod 0644 /usr/lib/tmpfiles.d/sshd.conf
systemd-tmpfiles --create /usr/lib/tmpfiles.d/sshd.conf

mv /usr/bin/ssh 		/usr/bin/ssh_$openssh_version_num
mv /usr/bin/scp 		/usr/bin/scp_$openssh_version_num
mv /usr/sbin/sshd 		/usr/sbin/sshd_$openssh_version_num
mv /usr/bin/ssh-add 		/usr/bin/ssh-add_$openssh_version_num
mv /usr/bin/ssh-agent 		/usr/bin/ssh-agent_$openssh_version_num
mv /usr/bin/ssh-keygen 		/usr/bin/ssh-keygen_$openssh_version_num
mv /usr/bin/ssh-keyscan 	/usr/bin/ssh-keyscan_$openssh_version_num

update-alternatives --install /usr/bin/ssh       	ssh       	/usr/local/openssh/bin/ssh		9
update-alternatives --install /usr/bin/scp     		scp        	/usr/local/openssh/bin/scp		9
update-alternatives --install /usr/sbin/sshd     	sshd        	/usr/local/openssh/sbin/sshd    	9
update-alternatives --install /usr/bin/ssh-add     	ssh-add         /usr/local/openssh/bin/ssh-add		9
update-alternatives --install /usr/bin/ssh-agent    	ssh-agent       /usr/local/openssh/bin/ssh-agent	9
update-alternatives --install /usr/bin/ssh-keygen   	ssh-keygen      /usr/local/openssh/bin/ssh-keygen	9
update-alternatives --install /usr/bin/ssh-keyscan  	ssh-keyscan     /usr/local/openssh/bin/ssh-keyscan	9

systemctl daemon-reload
systemctl restart sshd
systemctl enable sshd

echo "+--------------------------------------------------------------------------------------------------------------+"
echo "|                                          OpenSSH 9.7p1 Install Sucesses                                      |"
echo "+--------------------------------------------------------------------------------------------------------------+"

5. 编辑更新脚本update.sh

[root@localhost openssh]# vi update.sh 

#!/bin/bash
###########################################################################################
#  @programe  : openssh_update.sh 
#  @version   : 0.0.1                                                       
#  @function@ : 
#  @campany   : 
#  @dep.      :                                         
#  @writer    : Liu Cheng ji                                              
#  @date      : 2024-02-04                                              
############################################################################################
if [ -d "/usr/local/openssh" ]; then
	rm -rf /usr/local/openssh
	tar -zxvf openssh.tar.gz -C /usr/local/
else
	tar -zxvf openssh.tar.gz -C /usr/local/
fi
echo "+--------------------------------------------------------------------------------------------------------------+"
echo "|                                       	    OpenSSH is updated 9.7p1                                         |"
echo "+--------------------------------------------------------------------------------------------------------------+"

6.查看config目录

[root@localhost openssh]# cd config

[root@localhost config]# ls

sshd.conf  sshd.service

7. 编辑sshd.service文件

[root@localhost config]#vi sshd.service

[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target

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

[Install]
WantedBy=multi-user.target

8.编辑sshd.conf文件

[root@localhost openssh]# vi sshd.conf

d /var/empty/sshd 0711 root root

9.安装OpenSSH

[root@localhost openssh]# ./setup.sh

10.查看更新后的OpenSSH版本

[root@localhost ~]# ssh -V

OpenSSH, OpenSSL 3.2.1 30 Jan 2024

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mindfulness code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值