#!/usr/bin/env bash
#

# 显示当前ssh版本
ssh -V
sshd -V

# 备份
cp -a /etc/pam.d/sshd /etc/pam.d/sshd$(date +%Y%m%d)
cp -a /usr/bin/ssh /usr/bin/ssh$(date +%Y%m%d)
cp -a /usr/sbin/sshd /usr/sbin/sshd$(date +%Y%m%d)
cp -a /etc/ssh /etc/ssh$(date +%Y%m%d)

#检验
ls /etc/pam.d/sshd*
ls /usr/bin/ssh*
ls /usr/sbin/sshd*
ls /etc/ssh*

# 安装openssl-1.1.1w
rpm -ivh openssl-1.1.1w-1.el7.x86_64.rpm --nodeps --force
rpm -ivh openssl-devel-1.1.1w-1.el7.x86_64.rpm --nodeps --force

# 安装openssh-9.9
chown root.root /etc/ssh/ssh_host_ed25519_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_rsa_key

rpm -Uvh openssh-* --nodeps --force

cp -a /etc/pam.d/sshd$(date +%Y%m%d) /etc/pam.d/sshd

# 显示更新后的ssh版本
ssh -V
sshd -V
#systemctl restart sshd

# 回滚
# cp -a /usr/bin/ssh$(date +%Y+%m+%d) /usr/bin/ssh
# cp -a /usr/sbin/sshd$(date +%Y+%m+%d) /usr/sbin/sshd