升级OpenSSH版本(8.8版本)

1.前言

Hello大家好我是哈皮,最近项目中被报告低版本SSH存在漏洞,需要进行升级(升级到目前最新的8.8版本),记录一下升级过程。

2.资源

https://github.com/openssh/openssh-portable/tags
https://github.com/openssl/openssl/tags
# 我的版本
https://github.com/happyjava007/share/raw/main/openssh-8.8p1.tar.gz
https://github.com/happyjava007/share/raw/main/openssl-3.0.1.tar.gz

3.开启Telnet登陆

为了避免升级失败,导致无法登陆服务器,所以需要开启Telnet登陆。

systemctl start telnet.socket
telnet 127.0.0.1 # 测试是否可以正常登陆

4.升级OpenSSL

# 备份
mv /usr/bin/openssl /usr/bin/openssl_old

# 进入OpenSSL源码目录
./config shared && make && make install

# 检查安装
openssl version
# 报错
# openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
# 在OpenSSL源码目录
cp libssl.so.3 /usr/lib64/
cp libcrypto.so.3 /usr/lib64/

5.升级OpenSSH

# 备份
mkdir /etc/ssh_old
mv /etc/ssh/* /etc/ssh_old/

# 进入openssh目录
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/lib64/ --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux

# 警告
PAM is enabled. You may need to install a PAM control file 
for sshd, otherwise password authentication may fail. 
Example PAM control files can be found in the contrib/ 
subdirectory

ls contrib # 里面有各种系统

# 备份
mv /etc/pam.d/sshd /etc/pam.d/sshd_bak
# 复制
cp contrib/redhat/sshd.pam /etc/pam.d/sshd # 根据系统选择

# 安装
make && make install

# 根据提示执行
/usr/sbin/sshd -t -f /etc/ssh/sshd_config

vim /etc/ssh/sshd_config
PermitRootLogin yes # 开启root登陆

# 移除旧版本的文件
mv /usr/lib/systemd/system/sshd.service /etc/ssh_old/
mv /usr/lib/systemd/system/sshd.socket /etc/ssh_old/

cp -a contrib/redhat/sshd.init /etc/init.d/sshd

systemctl daemon-reload
systemctl restart sshd

升级完后,ssh登陆可能报错

Host key verification failed.

执行以下命令即可

ssh-keygen -R <server_ip>
posted @ 2022-01-29 16:16  happyjava  阅读(839)  评论(0编辑  收藏  举报