好像因为退出 xshell 有问题,导致再连接远程连接服务器的时候,就报如下错误:
Network error: Connection refused
一、根本问题
是远程连接无法连上的提示,也就是ssh的问题!!!
无法远程连接意味着无法使用命令行、无法上传文件、无法连接到数据库(我们数据用ssh连接)
二、寻求解决工具
然后最后在阿里云后台找到能使用远程命令的工具:
![905a3e82bf89026e29e00cd4f9be0ffb.png](https://img-blog.csdnimg.cn/img_convert/905a3e82bf89026e29e00cd4f9be0ffb.png)
或者
![93f4f3f8dc0924f6c1276b5586ba51b0.png](https://img-blog.csdnimg.cn/img_convert/93f4f3f8dc0924f6c1276b5586ba51b0.png)
三、查找问题根源
然后使用命令来查看到底是什么问题导致的
查看ssh的运行状态:systemctl status sshd.service
发现ssh没有运行,于是尝试运行ssh:systemctl restart sshd.service
发现还是不行,根据报错提示运行命令查看问题所在: /usr/sbin/sshd -T
显示是 在 /etc/ssh/sshd_config 文件的 151 行 UseDNS no 的问题
查找资料,修改文件等等,最后是先把配置文件的
Subsystem sftp internal-sftp
Match User wwwroot
ChrootDirectory /home/wwwroot
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
放在 UseDNS no 的后面
还是不行。
四、成功解决
于是我就注注释 UseDNS no。注释之后,发现报UseDNS no 的下一行的错误,于是就想到是ssh的配置文件问题了,就把
#UseDNS no
#AddressFamily inet
#PermitRootLogin yes
#SyslogFacility AUTHPRIV
#PasswordAuthentication yes
都注释掉了。
最后 运行 systemctl restart sshd.service
成功了!