最近公司有需求将redhat的openssh升级到新版本(7.4p1 -> 8.2p1),经过近一周时间的努力,终于初步完成了这个工作,在此做记录已供后续回查。
零、引用连接
https://www.jianshu.com/p/e75300b7e8be 参考文献,虽然步骤有点乱但是也算是有用
https://help.aliyun.com/knowledge_detail/41481.html?spm=a2c6h.13066369.0.0.6d391538l8zhMv 解决密码被拒绝的问题
一、准备工作
从官网下载最新版的openssh-8.2p1.tar.gz
准备rhel-server-7.5-x86_64-dvd.iso用于使用yum安装依赖
二、具体升级步骤
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(注:如果不安装这个,编译可能无法通过)
# 安装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<
9.确认ssh服务状态
# 启用sshd服务
systemctl enable sshd
# 重启服务
systemctl restart sshd
# 查看服务状态
systemctl status sshd
10.因为修改selinux配置,需要重启系统
reboot
完成升级!
三、一键升级脚本
为了简化工作,我编写了一个一键升级脚本用于完成这些繁琐的工作。
https://download.csdn.net/download/b7995547/12397549