RHEL7.6升级openssh8.6p1版

数据库服务器升级 openssh,原版本是 openssh_7.4p1,升级到官方最新发布的 openssh8.6p1版本

升级步骤
一、挂载镜像文件
二、配置本地yum源
三、安装telnet
yum -y install telnet*
yum -y install xinetd      # 网络守护进程服务
systemctl start telnet.socket
systemctl start xinetd
systemctl enable telnet.socket
systemctl enable xinetd.service
四、在防火墙上开放telnet端口
firewall-cmd --zone=public --add-port=23/tcp --permanent
firewall-cmd --reload  # 加载配置生效

或关闭防火墙

systemctl stop firewalld  # 关闭防火墙
systemctl disable firewalld  # 开机时禁用防火墙
五、telnet登陆系统

使用 telnet 登录系统, 默认不可以直接使用 root 用户登录, 使用普通用户登录后 su - root,后续操作在telnet界面实施。

六、下载openssh

软件包下载地址:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

mkdir /tmp/openssh  # 创建存放目录

将下载好的 openssh-8.6p1.tar.gz 软件拷贝至/tmp/openssh 目录下。

cd /tmp/openssh
tar xvf openssh-8.6p1.tar.gz # 解压文件到目录
七、安装编译开发环境
yum install -y openssl-devel gcc perl pam pam-devel zlib zlib-devel
八、备份配置文件
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /etc/ssh/ssh_config /etc/ssh/ssh_config.bak
cp -R /etc/pam.d/ /etc/pam.d.bak/
九、卸载原有openssh软件包
  • 首先查看安装了哪些软件包
rpm -qa | grep openssh
  • 依次卸载
yum remove openssh-clients-7.4p1-16.el7.x86_64
yum remove openssh-7.4p1-16.el7.x86_64
yum remove openssh-server-7.4p1-16.el7.x86_64
十、安装openssh

进入cd /tmp/openssh/openssh-8.6p1目录下,安装openssh

mkdir /usr/local/openssh  # 创建目录
./configure --prefix=/usr/local/openssh/ --sysconfdir=/etc/ssh --with-md5-passwords --with-pam  --with-zlib --with-privsep-path=/var/lib/sshd
chmod 600 /etc/ssh/ssh_host*  # 修改权限
make && make install  # 安装
十一、修改配置文件
1. 拷贝文件,在/tmp/openssh/openssh-8.6p1目录下执行
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
cp sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
chkconfig --list sshd
2. 编辑/etc/init.d/sshd
vim /etc/init.d/sshd

/usr/local/openssh/是openssh安装目录

  • 修改第25行 SSHD=/usr/sbin/sshd 为 SSHD=/usr/local/openssh/sbin/sshd image.png
  • 修改第41行 /usr/sbin/ssh-keygen -A 为 /usr/local/openssh/bin/ssh-keygen – A image.png
  • 第48行下增加一行 OPTIONS="-f /etc/ssh/sshd_config" ( “=” 后面不能有空格否则 ssh 无法启动) image.png
3. 编辑/etc/ssh/sshd_config
  • 修改如下信息:默认是被注释掉的,如果不修改用root用户SSH登录时没有密码保护,可直接登录,将注释取消掉后,root用户不能直接SSH登录,使用普通用户输入密码可以登录,建议取消注释。
  • 去掉第32行#PermitRootLogin prohibit-password image.png
  • 如果需要使用 winSCP 上传文件的话,必须修改要不然软件不能连接服务器
  • 修改第109行 Subsystem sftp /usr/libexec/sftp-server 修改为Subsystem sftp /usr/local/openssh/libexec/sftp-server
  • image.png
  • 在最后一行插入 PermitRootLogin yes image.png
十二、 启动openssh
systemctl daemon-reload
cd /
修改文件权限, 提示是否覆盖按“y”
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key   “y”后两次回车
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_rsa_key
systemctl restart sshd
systemctl daemon-reload
检查ssh版本
ssh -V
十三、关闭telnet服务
systemctl stop xinetd
systemctl disable xinetd
systemctl stop telnet.socket
systemctl disable telnet.socket
最后使用ssh登陆, root用户不能直接登陆,先登陆普通用户根据需求再 su - root