27

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.

2 Answers 2

28

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.

3
  • 1
    Would never have thought that the preview version would be the problem. Uninstalled it and everything works now. It did prompt me to update to it again in the terminal but guess I'll have to wait for them to fix this. Thanks for the quick help!
    – Isak
    Commented Apr 6, 2022 at 2:06
  • @Isak Excellent - Glad I could help! Commented Apr 6, 2022 at 2:36
  • 3
    This actually does work, tested with Windows 11 21H2. Re-installing wsl is a tad harder, there is no wsl --install --inbox command, but after uninstalling wsl you can visit aka.ms/wsl2kernel and install the provided update. I'm not sure if this played a part, but I also installed a non-store version of Ubuntu from the instructions "Downloading distributions" (rather than give you a URL that may change, google If the Microsoft Store app is not available, you can download and manually install Linux distributions) Commented Feb 24, 2023 at 19:07
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
2
  • Hi, When I do it as you say, I get into powershell terminal, and not WSL terminal Commented Jan 28, 2023 at 16:38
  • 1
    Works for me. @MaciejBledkowski did you systemctl enable --now ssh on your WSL2 instance?
    – blee
    Commented Apr 28, 2023 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .