'Vscode cannot connect to remote Linux (_WebSocket close with status code 1006)

Remote connection to Linux. After entering the password, there are two prompts on the right

coude not fetch remote environment failed to connect to the remote extension host server (error: websocket close with status code 1006)

And the terminal cannot input The remote directory could not be loaded I had tried countless times in many ways Reinstall vocode,delete ~/.vscode - server/ directory,and so on . What the hell should I do.

11

22



Solution 1:[1]

This can be resolved by rebooting the host machine (i.e. reboot your Windows PC) and restarting your WSL-2 box, then launching VSCode remote again.

No idea why this happens but from time to time I experience this issue.

Confirmed issue on:

Ubuntu 20.04
Vs code 1.60.1

Solution 2:[2]

  1. Find out which instance of WSL is running
wsl -l --running
  1. Terminate all running instances of WSL
wsl --shutdown
  1. Then simply restart WSL
wsl 

Solution 3:[3]

I changed the setting remote.WSL.server.connectThroughLocalhost (Settings -> Extensions -> Remote - WSL -> Connect Through Localhost) from disabled to enabled, and that fixed the issue for me.

No idea why this happened in the first place though, it was working fine without enabling this setting for over 2 months, and then suddenly it stopped working.

Maybe the IP of the virtual machine changed in some unexpected way?

Solution 4:[4]

Just clean up the /root/.vscode-server directory, vs code will create a new one when you connect again to the remote machine.

Solution 5:[5]

I have this issue all of a sudden and after a few trials, I found install another distro using WSL-1 fixes the problem. You can safely unregister the new distro afterwards.

Solution 6:[6]

I had this issue as well. I used @thnee's solution of changing the connection method. I found this easiest to do by using the settings UI > Remote > Connection Method

Solution 7:[7]

If anyone else comes across this question it's very easy.

  1. You're most likely using a reverse proxy
  2. Just enable websocket support on your reverse proxy.

Ex. If you are using Docker and the popular NGINX Proxy Manager; when you are adding a proxy host make sure to choose websocket support

No more 1006 error :)

Solution 8:[8]

I think that may cause by the conflict between ~/.ssh/config and ~/.ssh/known_hosts. I delete the ~/.ssh/known_hosts file and try again, find that the vscode can connect to remote successly

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Garbit
Solution 2 Basil
Solution 3 thnee
Solution 4 Jeevan Pawar
Solution 5 Dharman
Solution 6 Gib
Solution 7 wildernessfamily
Solution 8 Junjia Chen