移至新位置后,VScode SSH扩展会不断断开连接

问题描述

我最近搬到另一个国家,但是我在远程工作,因此我认为我的工作空间不会被打断。但是,现在我正尝试通过vscode中的ssh连接到我的工作区,因此连接一直保持断开状态。我通过工作空间提供的VPN连接到工作空间,虽然我可以通过ssh连接到工作的linux机器,但是却无法像过去几个月那样通过vscode-remote-ssh扩展连接到它。我的计算机上的设置没有任何变化。当我尝试在下面进行连接时,我附加了vscode提供的输出(这是重新连接尝试的输出,但第一次连接尝试看上去完全相同)。

[15:36:11.086] ------




[15:36:11.086] SSH Resolver called for "ssh-remote+203.0.113.0",attempt 2,(Reconnection)
[15:36:11.087] SSH Resolver called for host: 203.0.113.0
[15:36:11.087] Setting up SSH remote "203.0.113.0"
[15:36:11.091] Using commit id "e5e9e69aed6e1984f7499b7af85b3d05f9a6883a" and quality "stable" for server
[15:36:11.092] Install and start server if needed
[15:36:11.096] Using SSH config file "C:\Users\windowsUser\.ssh\config"
[15:36:11.096] Running script with connection command: ssh -T -D 53043 -F "C:\Users\windowsUser\.ssh\config" 203.0.113.0 bash
[15:36:11.101] Terminal shell path: C:\Windows\System32\cmd.exe
[15:36:11.240] > 
[15:36:11.240] Got some output,clearing connection timeout
[15:36:13.669] > linuxUser@203.0.113.0's password:
[15:36:13.670] Showing password prompt
[15:36:29.329] Got password response
[15:36:29.330] "install" wrote data to terminal: "*******"
[15:36:29.358] > 
> 
[15:36:31.047] > 3a294560e95d: running
> Acquiring lock on /home/linuxUser/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3
> d05f9a6883a/vscode-remote-lock.linuxUser.e5e9e69aed6e1984f7499b7af85b3d05f9a6883a
> 
[15:36:31.073] > Found existing installation at /home/linuxUser/.vscode-server/bin/e5e9e69aed6e1984
> f7499b7af85b3d05f9a6883a...
> Found running server...
> 
> *
> * Reminder: You may only use this software with Visual Studio family products,> * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
> *
> 
> Checking server status on port 34103 with wget
> 
[15:36:31.108] > 3a294560e95d: start
> 
[15:36:31.391] > sshAuthSock====
> listeningOn==34103==
> osReleaseId==ubuntu==
> arch==x86_64==
> webUiAccesstoken====
> tmpDir==/run/user/1000==
> platform==linux==
> 3a294560e95d: end
> 
[15:36:31.391] Received install output: 
sshAuthSock====
listeningOn==34103==
osReleaseId==ubuntu==
arch==x86_64==
webUiAccesstoken====
tmpDir==/run/user/1000==
platform==linux==

[15:36:31.392] Remote Server is listening on 34103
[15:36:31.392] Parsed server configuration: {"remoteListeningOn":{"port":34103},"osReleaseId":"ubuntu","arch":"x86_64","webUiAccesstoken":"","sshAuthSock":"","tmpDir":"/run/user/1000","platform":"linux"}
[15:36:31.393] Starting forwarding server. localPort 53048 -> socksPort 53043 -> remotePort 34103
[15:36:31.395] Forwarding server listening on 53048
[15:36:31.395] Waiting for ssh tunnel to be ready
[15:36:31.396] Tunneled 34103 to local port 53048
[15:36:31.396] Resolved "ssh-remote+203.0.113.0" to "127.0.0.1:53048"
[15:36:31.397] [Forwarding server 53048] Got connection 0
[15:36:31.402] ------




[15:36:31.430] [Forwarding server 53048] Got connection 1
[15:36:31.431] [Forwarding server 53048] Got connection 2

该连接在[Forwarding server 53048] Got connection 2上挂了几秒钟,然后断开与我的连接并重复此消息(然后再次要求输入密码)。我尝试从Linux计算机中删除.vscode-server文件,然后立即重新创建该文件,但仍然无法连接。我还尝试过更改vscode设置中的超时,但这也无济于事。我不确定为什么只是将计算机从一个位置物理移动到另一个位置而又保留在同一vpn后会发生这种情况,为什么我仍然能够通过常规ssh进行连接,而不能通过vscode-remote ssh扩展进行连接。 >

解决方法

我也有同样的问题,对我来说。 我没有解决方案,但解决方法cr脚-重新启动远端机器。 我正在运行ubuntu 20.04,并且一旦我重新启动,那么我可以从Visual Studio进行连接并且连接保持正常,但是一旦我关闭VSC并重新启动,然后又遇到此问题,那么我又不得不重新启动远程计算机。

编辑:后来我发现使用systemctl start / stop sshd停止sshd守护程序也可以解决这种情况-因此无需重新启动

,

您可以尝试手动 ssh 到服务器并删除远程服务器文件夹,这使 VSCode 重新从头开始下载。

这对我今天有帮助:

rm -rf ~/.vscode-server/
rm -rf ~/.vscode-remote/

建议来自以下讨论:https://github.com/microsoft/vscode-remote-release/issues/2513


您可能还想检查服务器的目标组中是否允许您的新网络 IP。