1,下载新版本的openssh(此处版本为9.0p1,建议将压缩包下载到/opt目录下)
cd /opt
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
2,下载完成后,解压压缩包
tar -zxvf openssh-9.0p1.tar.gz
3,查看opt目录
ll
4,卸载原有的ssh相关文件
yum remove openssh –y
5,手动删除原有ssh相关文件
rm -rf /etc/ssh/*
6,进入到自己解压到的ssh目录下
cd openssh-9.0p1/
7,安装编译
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl --with-zlib --with-md5-passwords --with-pam && make && make install
8,安装编译会可能发生以下问题
(1)若提示configure: error: *** zlib.h missing - please install first or check config.log ***,执行yum -y install zlib zlib-devel后重新进行安装编译
(2)若提示configure: error: *** working libcrypto not found, check config.log,执行yum install -y openssl-devel后重新进行安装编译
(3)若提示configure: error: PAM headers not found,执行yum -y install pam-devel后重新进行安装编译
9,安装成功显示如下
/usr/bin/install -c -m 644 ssh-sk-helper.8.out /usr/share/man8/ssh-sk-helper.8
/usr/bin/mkdir -p /etc/ssh
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
/usr/sbin/sshd -t -f /etc/ssh/sshd_comfig
10,安装成功之后再执行如下命令
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
service sshd restart
11,查看openssh版本
ssh -V
12,修改SSH登录端口(初始为22,统一改为10011)(此处设置端口为10011,根据实际情况设置)
(1)vi /etc/ssh/sshd_config
(2)找到#Port 22的注释,在上方写入Port 10011
(3)找到#PermitRootLogin prohibit-password,在下方写入PermitRootLogin yes
(4)重启ssh 命令为systemctl restart sshd