xshell无法连接SSH服务,误操作记录

记录一次大坑,ssh文件权限被误修改,手贱授权当前目录权限,被误操作授权给根目录(一个点之差),导致系统崩溃无法正常连接!只能利用VNC连接阿里云物理终端来解决!


如下图历史操作
在这里插入图片描述
排查过程如下:

首先通过物理终端进入到linux上, 查看系统日志/var/log/messages,发现报权限错误日志
在这里插入图片描述
使用rpm -V 命令可检查到ssh的软件包正常,但某个目录的属主错误。

[root@k8smaster ~]# rpm -V openssh-server
.....UG..  c /etc/pam.d/sshd
S.5..UGT.  c /etc/ssh/sshd_config
.....UG..  c /etc/sysconfig/sshd
.....UG..    /usr/lib/systemd/system/sshd-keygen.service
.....UG..    /usr/lib/systemd/system/sshd.service
.....UG..    /usr/lib/systemd/system/sshd.socket
.....UG..    /usr/lib/systemd/system/sshd@.service
.....UG..    /usr/lib64/fipscheck/sshd.hmac
.....UG..    /usr/libexec/openssh/sftp-server
.....UG..    /usr/sbin/sshd
.....UG..    /usr/sbin/sshd-keygen
.....UG..  d /usr/share/man/man5/moduli.5.gz
.....UG..  d /usr/share/man/man5/sshd_config.5.gz
.....UG..  d /usr/share/man/man8/sftp-server.8.gz
.....UG..  d /usr/share/man/man8/sshd.8.gz
.....UG..    /var/empty/sshd

经查看发现根目录的下所有目录属主都不是root,导致连接异常,主要/var/empty/目录属主被修改导致ssh连接不上

恢复原来的root属主

[root@k8smaster ~]# chown -R root. /*
[root@k8smaster ~]#  ll /var/empty/
总用量 0
drwx--x--x. 2 tomcat tomcat 6 89 2019 sshd

修改后还是连不到,尝试着重启ssh,又出现了其他错误
在这里插入图片描述
这是因为新版的opensshd 中添加了ed25519 做签名验证,而之前系统里没这个算法的证书。生成一下就好了
解决方法:

ssh-keygen -A
- 或者
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ED25519_key
- 然后
systemctl restart sshd

然后重新进行登录,发现日志出现了一个新的错误
在这里插入图片描述
修改密钥的访问权限

chmod 700 /etc/ssh/ssh_host_ed25519_key

在次重新启动,成功启动

[root@k8smaster ~]# chown -R  root. /var/empty/sshd/
[root@k8smaster ~]# chmod 711 /var/empty/sshd
[root@k8smaster ~]# systemctl restart sshd
[root@k8smaster ~]# netstat -lntp|grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      37872/sshd          
tcp6       0      0 :::22                   :::*                    LISTEN      37872/sshd 

至此,问题全部解决完了,登录没啥问题!感谢互联网

参考:文章

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐