Skip to content

Instantly share code, notes, and snippets.

@cicorias
Forked from mattbell87/remote-wsl.md
Created August 21, 2022 16:48
Show Gist options
  • Save cicorias/2e72348b53668e3fa21b61a804733862 to your computer and use it in GitHub Desktop.
Save cicorias/2e72348b53668e3fa21b61a804733862 to your computer and use it in GitHub Desktop.
VSCode Remote: Connect to WSL2 from another machine

VSCode Remote: Connect to WSL2 from another machine

Do you want to do remote development on your WSL2 container in Visual Studio Code? Read this.

Change your OpenSSH shell

SSH to your Windows host (SSH Server must be installed in Windows Features)

ssh user@windowshost

Start Powershell

powershell

Run this command to switch SSH from CMD to WSL

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\System32\bash.exe" -PropertyType String -Force

Test

ssh user@windowshost

You should now see WSL2 instead of CMD

Connect from VSCode

At this point you can connect to your Win10 host with Remote SSH in VSCode with your Windows username and pw. But you'll actually start and connect to WSL2.

  1. Install the Remote - SSH extension
  2. Add a new SSH target and connect with your Windows host, username and password (you will automatically log in as the Linux user)

Credit

The workaround was inspired by: https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment