CENTOS7 升级OPENSSH 到 8.5
一.升级原因
OpenSSH 7.7版本至7.9版本和8.1之前的8.x版本中存在输入验证错误漏洞。OpenSSH 8.5版本已修复该错误,因此将环境OpenSSH 升级到8.5。
二.升级步骤
2.1 安装telnet-server 以及 xinetd
(安装telnet登陆并操作openssh升级,以免ssh安装异常导致无法登陆)
yum install xinetd telnet-server -y
2.2 配置telnet登录的终端类型,在/etc/securetty 文件末尾增加一些pts终端,如下
cat >> /etc/securetty <<EOF
pts/0
pts/1
pts/2
pts/3
EOF
2.3 启动telnet服务,并设置开机自动启动
systemctl enable xinetd
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd
2.4 使用telnet 登陆,以后操作都是通过telnet
(任意支持telnet命令的系统,使用telnet xx.xx.xx.xx,输入账号密码登陆服务器)
2.5 备份现有ssh相关内容
(视服务器情况选择备份内容,便于问题恢复)
使用ps -ef|grep openssh 查看,并备份对应文件或者配置文件
2.6 准备OpenSSH原文件
wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.5p1.tar.gz
wget https://ftp.openssl.org/source/openssl-1.1.1k.tar.gz
2.7 准备编译环境
yum install -y gcc gcc-c++ glibc make autoconf openssl-devel pcre-devel pam-devel rpm-build
2.8 卸载由yum安装的ssh
yum remove openssh
卸载后使用ps -ef|grep openssh 查看原服务运行目录,未删除可以手动删除。
2.9 编译安装OpenSSL
tar xfz openssl-1.1.1k.tar.gz
cd openssl-1.1.1k
./config --prefix=/usr/local --openssldir=/usr/local/ssl
make && make install
./config shared --prefix=/usr/local --openssldir=/usr/local/ssl
make clean
make && make install
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl /usr/include/openssl
echo "/usr/local/lib" >> /etc/ld.so.conf
echo "/usr/local/lib64" >> /etc/ld.so.conf
/sbin/ldconfig
openssl version
2.9 编译安装OpenSSH
tar xfz openssh-8.5p1.tar.gz
cd openssh-8.5p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install
2.10 修改配置文件
vim /usr/local/openssh/etc/sshd_config
根据需求修改以下参数
PermitRootLogin yes ###允许root账号登陆
PubkeyAuthentication yes
PasswordAuthentication yes ###允许密码登陆
Port 22022
2.11 复制文件到对应系统目录
chkconfig --add sshd
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
(1.复制若出现文件覆盖选择,输入yes即可)
(2.若出现文件被使用无法覆盖报错,找到报错文件并手动删除)
2.12 启动SSH
service sshd restart
2.13 其他相关命令
1.重启命令
systemctl start sshd.service
或
systemctl restart sshd.service
2.查看状态
systemctl status sshd.service
3.启动服务
systemctl start sshd.service
4.开机自启
systemctl enable sshd.service
三.收尾
3.1 检验升级结果
ssh -V
成功升级结果显示:
OpenSSH_8.5p1, OpenSSL 1.1.1k 25 Mar 2021
3.2 停止telnet并卸载telnet
systemctl stop telnet.socket
systemctl stop xinetd
systemctl disable xinetd
systemctl disable telnet.socket
yum remove telnet-server xinetd