1、下载openssh-8.2p1.tar.gz
链接:https://pan.baidu.com/s/1nmcLV50a0W_hSLGzSvWufw
提取码:a8or
2、准备rhel-server-7.5-x86_64-dvd.iso用于使用yum安装依赖;(测试中虚机有外网直接用yum安装的)
3、https://help.aliyun.com/knowledge_detail/41481.html?spm=a2c6h.13066369.0.0.6d391538l8zhMv 解决密码被拒绝的问题
还有一个需要注意的就是,升级openssl很可能导致登陆不进去,所以一定要多开几个窗口,或者在虚拟化平台,处于登陆状态,避免升级完成后,登陆不进去,需要再调整;!!!
具体升级步骤
0.首先记录sshd.pid的目录,以供后续更改配置文件使用
# 查看sshd.pid路径
find / -name sshd.pid # 我这里是/run/sshd.pid
1.首先查看openssh现有版本
# 查看ssh版本
ssh -V # 我这里的版本是7.4p1
2.使用rpm删除现有的openssh。
# 删除现有openssh
rpm -e --nodeps $(rpm -qa | grep openssh)# 删除旧的配置文件
rm -rf /etc/ssh/*
3.安装openssl-devel(注:如果不安装这个,编译可能无法通过,根据实际情况,可能还需要安装gcc)
# 安装openssl-devel。-y:默认同意安装
yum -y install openssl-devel
4. 更改selinux配置
# enforcing -> permissive
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
我这里配置文件在/etc/selinux/config,如果你不确定你的配置文件路径,请使用下面的命令查询
/usr/sbin/sestatus -v
5.解压缩openssh-8.2p1.tar.gz,配置、编译、安装
# 解压缩
tar -zxvf openssh-8.2p1.tar.gz openssh-8.2p1# 进入目录
cd openssh-8.2p1# 编译安装前配置
./configure --prefix=/usr/ --sysconfdir=/etc/ssh/ --with-ssl-dir=/etc/ssl --with-md5-passwords --mandir=/usr/share/man/# 编译并安装
make && make install
6.配置ssh服务开机启动
# 复制启动文件至/etc/init.d/
cp -a contrib/redhat/sshd.init /etc/init.d/sshd# 编辑/etc/init.d/sshd文件, 将PID_FILE改为之前记下的sshd.pid路径
sed -i "s/PID_FILE=\/var\/run\/sshd.pid/PID_FILE=\/run\/sshd.pid/" /etc/init.d/sshd# 设置开机启动sshd
chkconfig sshd on
chkconfig --list sshd
7.编辑/etc/ssh/sshd_config, 设置一些常用参数
# 编辑/etc/ssh/sshd_config, 设置一些常用参数
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config
sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config
sed -i "s/#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config
sed -i "s/#AllowTcpForwarding yes/AllowTcpForwarding yes/" /etc/ssh/sshd_config
sed -i "s/#X11Forwarding no/X11Forwarding yes/" /etc/ssh/sshd_config
sed -i "s/#PidFile \/var\/run\/sshd.pid/PidFile \/run\/sshd.pid/" /etc/ssh/sshd_config
8.配置/etc/ssh/sshd_config文件(至于这个在干嘛,我其实也不太知道,可以不写,我这边操作时没有写)
# 配置/etc/ssh/sshd_config文件
cat>/usr/lib/systemd/system/sshd.service<<EOF
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
#After=network.target sshd-keygen.service
#Wants=sshd-keygen.service
After=network.target[Service]
#Type=notify
#EnvironmentFile=/etc/sysconfig/sshd
#ExecStart=/usr/sbin/sshd -D \$OPTIONS
ExecStart=/usr/sbin/sshd
#ExecReload=/bin/kill -HUP \$MAINPID
#KillMode=process
#Restart=on-failure
#RestartSec=42s[Install]
WantedBy=multi-user.targetEOF
9.确认ssh服务状态
# 启用sshd服务
systemctl enable sshd# 重启服务
systemctl restart sshd# 查看服务状态
systemctl status sshd
10.因为修改selinux配置,需要重启系统(不用重启)
reboot
完成升级!
原作者文档写的很细,避免失传了,我这边抄录一遍;