1、依赖软件包:
yum install wget gcc -y
yum install -y zlib-devel openssl-devel
yum install pam-devel libselinux-devel zlib-devel openssl-devel -y
2、下载安装包OpenSSH8.4上传至服务器或wget直接下载
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz
3、删除低版本OpenSSH的的rpm包
rpm -e --nodeps rpm -qa | grep openssh
rm -f /etc/ssh/*
4、安装openssh
(1)解压
tar -zxvf openssh-8.4p1.tar.gz
cd openssh-8.4p1
(2)配置
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl --without-hardening
(3)编译安装
make && make install
(4)赋权
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
(5)复制配置文件并设置允许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
echo ‘PermitRootLogin yes’ >> /etc/ssh/sshd_config
(6)添加添加自启服务ssh到开机启动项
chkconfig --add sshd
chkconfig sshd on
(7)重启服务
systemctl restart sshd
(8)查看下安装结果:
ssh -V
(9)测试是否可以ssh连接
错误处理
如果sshd服务状态提示:get shadow information for root。考虑是否是selinux启用了策略,将/etc/selinux/config 文件中的SELINUX=enforcing 修改为
sed -i ‘s/enforcing/disabled/g’ /etc/selinux/config
setenforce 0