Failed to connect to the remote extension host server(Error: WebSocket close with status code 1006)

问题截图

在这里插入图片描述

解决办法(第一种情况):

  • 首先,检查远程服务器上的 /etc/ssh/sshd_config里,有没有允许端口转发:AllowTcpForwarding yes
  • 更改后,重启 sshd服务:systemctl restart sshd。
  • 然后,删除~/.vscode-server目录
  • 本地Vscode settings的user配置里,把remote.SSH.remoteServerListenOnSocket的勾去掉(因为remote配置那里这个remoteServerListenOnSocket是关掉的),Remote: Auto Forward Ports前面的勾确认是打开的。成功连接上以后,本地和远程服务器的remote.SSH.remoteServerListenOnSocket的勾会自动打开。
  • 总结:连接的双方配置应该是对称的。先要保证服务器那边sshd_config端口转发打开,然后设置上remoteServerListenOnSocket都关闭,Remote: Auto Forward Ports都打开。成功连接上以后,remoteServerListenOnSocket的勾会自动打开,两边趁着现在ssh连接成功可以改,就都手动关了,否则又会出现连不上的问题。因为连不上的时候,remote那边不让改,就两头堵了。
  • 在这里插入图片描述

第二种情况:如果上面方法不行,那么就把远程服务器上的openssh更新一下,yum update openssh.

-wget,curl一般不用更新。他们是远程服务器上用来下载一些东西的,如果remote ssh扩展的输出日志中显示Downloading complete,我们就知道,其实wget,curl是没事的,问题不出在这里。
在这里插入图片描述

最后发现的第三种情况

  • ssh连不上的时候,settings里remote那边的配置不让改。
  • 实在不行,我把C:\Users\用户名\AppData\Roaming\Code下的东西全删了,然后把本地user配置里,remote.SSH.remoteServerListenOnSocket的勾去掉,因为remote那边的remoteServerListenOnSocket的勾是去掉的,然后再连就好了。

最后,当VScode连接成功后,日志为如下所示:

在这里插入图片描述