直接运行sh xxx.sh文件
#!/bin/bash
# 创建安装包存位置
mkdir /data
cd /data
# 安装编译环境
yum install wget gcc -y
yum install -y zlib-devel openssl-devel
yum install pam-devel libselinux-devel zlib-devel openssl-devel -y
# 没有安装包在下载,可直接更改对应的安装版本9.6
# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.6p1.tar.gz
# 解压
tar -zxvf /data/openssh-9.6p1.tar.gz
cd /data/openssh-9.6p1
# 删除低版本OpenSSH的的rpm包
rpm -e --nodeps `rpm -qa | grep openssh`
# 进入安装位置
cd openssh-9.6p1
# 配置
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl --without-hardening --without-openssl-header-check
# .编译安装
make
make install
# 赋权
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
# 复制配置文件并设置允许root用户远程登录
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod u+x /etc/init.d/sshd
# 修改配置
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
# 添加添加自启服务ssh到开机启动项
chkconfig --add sshd
chkconfig sshd on
# 重启服务
systemctl restart sshd
# 查看安装结果
ssh -V