首先查看当前版本 centos7 默认使用ssh
ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
安装依赖包
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pam-devel libselinux-devel wget
下载SSH9.3源码包
离线下载对应版本 openssh-9.3p1.tar.gz
在线下载对应版本 推荐
wget -c https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
mv openssh-9.3p1.tar.gz /opt && cd /opt
解压安装
tar -zxvf openssh-9.3p1.tar.gz #解压
cd openssh-9.3p1
#执行安装
./configure --with-md5-passwords --with-pam --with-selinux --with-privsep-path=/sshd --sysconfdir=/etc/ssh
#由于启用了PAM则需要安装一个配置文件,该文件在contrib目录下
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
#拷贝开机启动脚本
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
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
如果编译完成不授权文件权限则会报如下错误,需提升对应文件夹权限
修改配置文件 允许root远程登录
将PermitRootLogin prohibit-password 修改为 PermitRootLogin yes
vim /etc/ssh/sshd_config
PermitRootLogin yes
关闭DNS选项加快访问
PubkeyAuthentication yes
注释下面2个配置
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials no
检查ssh配置 无报错即为正常
#检查是否有配置错误
sshd -t
启动服务
systemctl restart sshd
systemctl enable sshd
systemctl status sshd
查看openssh版本
ssh -V
最后自行远程登录验证