29

I have two machines; a desktop and a laptop. The desktop runs WSL2 and an OpenSSH server on the Windows side. I'm able to connect to the SSH server from the laptop without any problems but not able to start WSL over the SSH connection. When I run wsl or bash the following message prints: The file cannot be accessed by the system. Note that I can start WSL from the terminal directly on the desktop (but not if I SSH into the desktop from the desktop).

This is so weird, I have no idea what could be the problem. I have tried searching for a similar problem but haven't found anything.

Isak
  • 425

2 Answers2

30

Short answer: This is now (mostly) fixed in the WSL 2.0.0 pre-release application.

Background

This is something that worked in the original WSL1 and WSL2 that came as a Windows feature.

Then it didn't work when WSL became available as an application.

Now, it's possible once again starting with the 2.0.0 pre-release of WSL.

To update to 2.0.0 pre-release

If you'd like to update, first make sure you are using a recent version of WSL. From PowerShell:

wsl --version

If it returns version information, then you are good to go. If not, you need to install WSL from the Microsoft Store.

Next, run:

wsl --update --pre-release

After updating, a reboot is recommended.

To run WSL via SSH in 2.0.0

Things work a little bit differently at the moment. To run WSL from SSH (using 2.0.0), you'll need to use:

From PowerShell:

& 'C:\Program Files\WSL\wsl.exe'

From CMD:

"c:\Program Files\WSL\wsl.exe"

Note that the WSL development team has stated that they are working on providing this capability for the base wsl.exe command as well.

NotTheDr01ds
  • 28,025
10

A solution to still access WSL2 from a remote machine is to set up ssh in wsl and add the client's public key to wsl, and then use the ssh ProxyJump option:

ssh -J <windows_host_username>@<ip_windows_host> <wsl_username>@localhost
DV_33
  • 101