###调整yum源为阿里云
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum clean all
sudo yum makecache
###升级openssh###
setenforce 0
vi /etc/selinux/config
#SELINUX=disabled
###安装gcc依赖
yum -y install gcc*
###安装perl5###
mkdir /home/file
cd /home/file
wget https://www.cpan.org/src/5.0/perl-5.28.0.tar.gz
tar -xzf perl-5.28.0.tar.gz
cd perl-5.28.0
./Configure -des -Dprefix=/usr/local/perl
make & make install
####安装openssl####
#备份老版本
whereis openssl
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
#卸载
yum remove openssl
#下载安装openssl
wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz --no-check-certificate
tar -xzvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w/
./config --prefix=/usr
make && make install
#查询验证版本
whereis openssl
openssl version
#####安装openssh#####
#安装源码编译依赖包
yum install pam-devel openssl-devel zlib zlib-devel
#备份SSH相关配置
cp /etc/ssh/sshd_config /home/sshd_config.backup
cp /etc/pam.d/sshd /home/sshd.backup
#卸载SSH
rpm -qa | grep openssh
rpm -e --nodeps openssh-7.4p1-23.el7_9.x86_64
rpm -e --nodeps openssh-server-7.4p1-23.el7_9.x86_64
rpm -e --nodeps openssh-clients-7.4p1-23.el7_9.x86_64
#rpm -e --nodeps openssh-server-7.4p1-11.el7.x86_64
#rpm -e --nodeps openssh-7.4p1-11.el7.x86_64
#rpm -e --nodeps openssh-clients-7.4p1-11.el7.x86_64
#rpm -e --nodeps openssh-6.6.1p1-31.el7.x86_64
#rpm -e --nodeps openssh-server-6.6.1p1-31.el7.x86_64
#rpm -e --nodeps openssh-clients-6.6.1p1-31.el7.x86_64
#下载openssh9.7源码
wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz
#解压、编译
tar -xf openssh-9.7p1.tar.gz
cd openssh-9.7p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssldir=/usr/ssl --without-hardening
make && make install
#设置相关文件权限
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
#复制配置文件
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
chmod u+x /etc/init.d/sshd
#还原配置
mv /home/sshd.backup /etc/pam.d/sshd
mv /home/sshd_config.backup /etc/ssh/sshd_config
#修改/etc/ssh/sshd_config配置文件,打开下面配置文件,去掉下面两句的注释
vim /etc/ssh/sshd_config
#PermitRootLogin yes
#PubkeyAuthentication yes
#添加自启服务 ssh 到开机启动项
chkconfig --add sshd
chkconfig sshd on
#重启ssh服务
systemctl restart sshd
#查看版本
ssh -V