TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

CentOS 7升级openssh 9.8完整过程

Laughing博主
2024-07-30
/
0 评论
/
567 阅读
/
442 个字
/
百度已收录
07/30
本文最后更新于2024年07月30日,已超过44天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

CentOS 7自带的openssh版本是1.0.2,版本号很低,最近服务器被公司扫描出来有不少相关的中高危漏洞,所以只能升级到最新版本。

壹、安装openssl1.1.1及以上版本

因为 OpenSSH 9.8p1 需要 OpenSSL 的版本 >= 1.1.1,所以需要安装 openssl11

安装编译 OpenSSL 所需的包,包括 gcc、make、perl 和 zlib-devel。可以通过运行以下命令完成:

yum install -y gcc make perl zlib-devel

下载 OpenSSL 1.1.1 的源码包,可以从 OpenSSL 官网下载(https://www.openssl.org/source/openssl-1.1.1.tar.gz)或使用以下命令下载:

wget https://www.openssl.org/source/openssl-1.1.1.tar.gz

解压源码包并进入解压后的目录:

tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1  

初始化并编译、安装 OpenSSL:

./config   --prefix=/opt/openssl-1.1.1
make
make install

添加环境变量

vim /etc/profile
export PATH=/opt/openssl-1.1.1/bin:$PATH
export LD_LIBRARY_PATH=/opt/openssl-1.1.1/lib:$LD_LIBRARY_PATH

使配置文件生效

source /etc/profile

这会在系统中安装新的 OpenSSL 版本。可以通过运行以下命令检查 OpenSSL 版本:

openssl version

如果输出结果中的版本号为 1.1.1 或更高版本,则说明 OpenSSL 已成功升级。

如果还是原来的版本,没变成新版本,可以做软连接使其挂用新版本 ,将原来的openssl,做备份

mv /usr/bin/openssl     /usr/bin/openssl_20240730bak
mv /usr/lib64/openssl   /usr/lib64/openssl_20240730bak

然后将新安装的OpenSSL做软连接到这个路径

ln  -s  /opt/openssl-1.1.1/bin/openssl   /usr/bin/openssl

再执行以下命令检查 OpenSSL 版本:

openssl version

贰、安装openssh

可以从Open SSH: 官网GitHub Releases下载,上传到服务器指定位置

tar -zxvf openssh-portable-V_9_8_P1.tar.gz

进入目录

cd openssh-portable-V_9_8_P1    

依次执行下面命令进行编译、安装,注意LDFLAGS需要是我们openssl 1.1.1对应的位置

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/opt/openssl-1.1.1 --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening
make
make install

查看是否安装成功

ssh -V

如果输出正确的版本,则代表安装正确

OpenSSH_9.8p1, OpenSSL 1.1.1  11 Sep 2018

复制并修改启动sshd.init脚本

# 从源码目录下复制sshd.init到/etc/init.d/
cp contrib/redhat/sshd.init /etc/init.d/
 
## 查看并修改SSHD的新路径,将新的openssh安装路径更新
cat /etc/init.d/sshd.init | grep SSHD
sed -i "s/SSHD=\/usr\/sbin\/sshd/SSHD=\/usr\/local\/openssh\/sbin\/sshd/g" /etc/init.d/sshd.init
cat /etc/init.d/sshd.init | grep SSHD
 
## 查看并修改ssh-keygen的新路径,将新的ssh-keygen安装路径更新
cat -n /etc/init.d/sshd.init | grep ssh-keygen
sed -i "s#/usr/bin/ssh-keygen -A#/usr/local/openssh/bin/ssh-keygen -A#g" /etc/init.d/sshd.init
cat -n /etc/init.d/sshd.init | grep ssh-keygen

修改配置文件

# 开启允许X11转发
echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
# 开启允许密码验证
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
# 允许root登录
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

启动openssh,并设置开机启动

# 复制ssh的相关命令
cp -arp /usr/local/openssh/bin/* /usr/bin/
# 启动sshd服务
/etc/init.d/sshd.init
# 查看版本
ssh –V
# 添加开机启动
chmod +x /etc/rc.d/rc.local
echo "/etc/init.d/sshd.init start" >> /etc/rc.d/rc.local
朗读
赞(0)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/blog/the-complete-process-of-upgrading-centos-7-to-openssh-98.html(转载时请注明本文出处及文章链接)

评论 (0)