先去下载OpenSSH https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
上传到服务器解压 tar xfz openssh-8.6p1.tar.gz 文件
可能文件默认显示uid和gid数组都是1000,这里重新授权下。不授权可能也不影响安装(请自行测试)
chown -R root.root /root/openssh-8.6p1 可能文件默认显示uid和gid数组都是1000,这里重新授权下。不授权可能也不影响安装(请自行测试)
升级之前先备份数据
备份ssh:
mv /etc/ssh /etc/sshbak
mv /usr/bin/ssh /usr/bin/sshbak
mv /usr/sbin/sshd /usr/sbin/sshdbak
删除掉以前的ssh
rm -rf /etc/ssh/*
切换到openssh-8.6p 下面 执行
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/openssl/include --with-ssl-dir=/usr/local/openssl --with-zlib --with-md5-passwords --with-pam && make && make install
显示以下信息表示完成:
安装完毕 检查下结果 0为成功。
修改配置文件最终为如下内容,其他的不要动vim /etc/ssh/sshd_config
(1.修改#PermitRootLogin prohibit-password项,去掉注释#并把prohibit-password改为yes,修改后即为PermitRootLogin yes
(2.去掉注释#PasswordAuthentication yes变为PasswordAuthentication yes
(3.去掉注释#UseDNS no变为UseDNS no
验证配置
grep "^PermitRootLogin" /etc/ssh/sshd_config
grep "UseDNS" /etc/ssh/sshd_config
从原先的解压的包中拷贝一些文件到目标位置(如果目标目录存在就覆盖)
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
添加添加自启服务ssh到开机启动项
chkconfig --add sshd
systemctl enable sshd 这条报下面的错不用管
把原先的systemd管理的sshd文件删除或者移走或者删除,不移走的话影响我们重启sshd服务
设置sshd服务开机启动
chkconfig sshd on
查看下安装结果:
接下来测试启停服务。都正常
以后管理sshd通过下面方式了
/etc/init.d/sshd restart
netstat -lntp
/etc/init.d/sshd stop
netstat -lntp
/etc/init.d/sshd start
netstat -lntp
如果升级失败回退:
还原备份ssh:
mv /etc/sshbak /etc/ssh
mv /usr/bin/sshbak /usr/bin/ssh
mv /usr/sbin/sshdbak /usr/sbin/sshd
重启sshd服务:
service sshd restart