microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.26k stars 812 forks source link

Cannot start wsl in ssh session. #7900

Open Domain opened 2 years ago

Domain commented 2 years ago

Version

Microsoft Windows [版本 10.0.22523.1000]

WSL Version

Kernel Version

5.10.74.3

Distro Version

Ubuntu 21.10

Other Software

OpenSSH_for_Windows_8.6p1, LibreSSL 3.3.3

Repro Steps

  1. Connect to windows 10 over ssh
  2. type wsl to start

Expected Behavior

wsl start successful

Actual Behavior

Only output: the file cannot be accessed by the system

Diagnostic Logs

No response

benhillis commented 2 years ago

Are you using the version of WSL from the Microsoft Store?

benhillis commented 2 years ago

If so, this is a known issue: https://docs.microsoft.com/en-us/windows/wsl/store-release-notes#known-issues

Domain commented 2 years ago

Are you using the version of WSL from the Microsoft Store? If so, this is a known issue: https://docs.microsoft.com/en-us/windows/wsl/store-release-notes#known-issues

Oh, yes, I just upgrade to the store version.

ppigazzini commented 2 years ago

I successfully reverted uninstalling from "Apps and Features" the 2 apps WSL and gWSL installed with the Microsoft Store "Windows Subsystem for Linux Preview" (after exporting my distros as backup).

Domain commented 2 years ago

I successfully reverted uninstalling from "Apps and Features" the 2 apps WSL and gWSL installed with the Microsoft Store "Windows Subsystem for Linux Preview" (after exporting my distros as backup).

👍, thanks for the tips!

kansson commented 2 years ago

Will this ever be fixed?

barak14 commented 2 years ago

I would like to be able to use WSL2g when i am using the machine locally and SSH when I need to remote in. It's a better experience than having to RDP into my windows machine to access the WSL filesystem. Is this likely to be fixed?

zzjin commented 2 years ago

Uninstall from store version, and install wsl from command line works, but windows 11 will automated upgrade to store version after some update leases. Any update here to reslove https://docs.microsoft.com/en-us/windows/wsl/store-release-notes#known-issues ?

Domain commented 1 year ago

Any update on this issue? I need systemd and ssh!

mg-christian-axelsson commented 1 year ago

I'm running into this issue after upgrading to Win11 22H2

gurnec commented 1 year ago

Just to clarify an earlier comment, it's only necessary to remove the Windows Store app to restore SSH capability. After doing a backup with wsl --export, open Start, search for Windows Subsystem for Linux Preview, and select Uninstall from the bottom right.

It's not necessary to remove (or at least it wasn't for me) Windows Subsystem for Linux Update nor Windows Subsystem for Linux WSLg Preview from Apps > Installed Apps.

You can check by running wsl --status. With the Windows Store app installed, it should look similar to:

Default Distribution: Ubuntu
Default Version: 2
WSL version: 0.66.2.0
Kernel version: 5.15.57.1
WSLg version: 1.0.42
MSRDC version: 1.2.3401
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.521

Without it installed:

Default Distribution: Ubuntu
Default Version: 2

Windows Subsystem for Linux was last updated on 3/25/2022
WSL automatic updates are on.

Kernel version: 5.10.102.1
ddddavid-he commented 1 year ago

I'm running into this issue after upgrading to Win11 22H2

I do too after upgrading to 22H2 and wsl2 kernel 5.15

kansson commented 1 year ago

Is there some technical limitation why this isn't worked on?

lxg208 commented 1 year ago

I need to use the store version for the stick keys bug (https://github.com/microsoft/wslg/issues/899). And I need to ssh into my machine. Can we fix both bugs? It has been more than a year.

davidleechen commented 1 year ago

Confirming this issue still exists on Windows 11 22H2 22621.1105. I was prompted inside WSL2 to update to the store version, and did so, then lost the ability to ssh. Uninstalling the store version fixed the problem. This was the non-preview GA version.

Dash commented 1 year ago

Not sure if there is anyway of getting this voted for, so I'll leave a comment.

To run a docker daemon in WSL you need systemd, which as you may have guessed it, needs the store version of WSL to enable. And yep, once that's done you can no longer access WSL via the Windows SSH host.

mg-christian-axelsson commented 1 year ago

Not sure if there is anyway of getting this voted for, so I'll leave a comment.

To run a docker daemon in WSL you need systemd, which as you may have guessed it, needs the store version of WSL to enable. And yep, once that's done you can no longer access WSL via the Windows SSH host.

You don't need systemd to run daemons. Stick something like

[boot]
command = service docker start

into /etc/wsl.conf and it will work. I'm not arguing that it's more pretty or better than a systemd setup but it gets the job done.

ndevenish commented 1 year ago

Confirming this issue still exists on Windows 11 22H2 22621.1105. I was prompted inside WSL2 to update to the store version, and did so, then lost the ability to ssh. Uninstalling the store version fixed the problem. This was the non-preview GA version.

Exactly same situation here. I was prompted to upgrade:

Windows Subsystem for Linux is now available in the Microsoft Store!
You can upgrade by running 'wsl.exe --update' or by visiting https://aka.ms/wslstorepage
Installing WSL from the Microsoft Store will give you the latest WSL updates, faster.
For more information please visit https://aka.ms/wslstoreinfo

and this disabled my access.

Adelrisk commented 1 year ago

My workaround worked as follows:

  1. Remove all subsystems and linux distributions from Apps and Features (aka Store installs)
  2. (Re-)install wsl using the steps for older versions of WSL

I wish you luck :four_leaf_clover:

shusso commented 1 year ago

My workaround worked as follows:

  1. Remove all subsystems and linux distributions from Apps and Features (aka Store installs)
  2. (Re-)install wsl using the steps for older versions of WSL

I wish you luck 🍀

Confirming that this worked for me. The only difference was that I removed the "Window subsystem for linux" app from the Start Menu.

andreyrd commented 1 year ago

Any explanation/workaround? Some of us need to use the Store version.

lxg208 commented 1 year ago

My workaround worked as follows:

  1. Remove all subsystems and linux distributions from Apps and Features (aka Store installs)
  2. (Re-)install wsl using the steps for older versions of WSL

I wish you luck 🍀

Confirming that this worked for me. The only difference was that I removed the "Window subsystem for linux" app from the Start Menu.

Unfortunately, the preview version solves the sticky key problem for me, the benefit of using preview version outweighs older version. I'm wondering why this fix is not ported back.

For "sticky" issue, see, e.g. https://github.com/microsoft/WSL/issues/6955

barak14 commented 1 year ago

I followed this to get SSH working with the preview version, by enabling sshd on WSL2 and Windows: https://www.reddit.com/r/bashonubuntuonwindows/comments/t2x1pc/my_lab_notes_to_configure_ssh_access_into_wsl_1/ Although I think i just start sshd using wsl.conf

ssh config on client PC:

Host wsl
  Hostname localhost
  Port 2022
  User username
  ProxyJump remote-pc
  UserKnownHostsFile ~\.ssh\wsl

ssh config on server:

Host localhost
  User username
  Port 2022
  IdentityFile ~\.ssh\id_rsa
nick-phillips commented 1 year ago

Just adding that @gurnec's recommendation to remove the Windows Subsystem for Linux app using Add or Remove Programs worked for me. I updated wsl to get systemd support for wsl on Windows 10, didn't realize the headaches it would cause.

Removing the app did not delete my distros, but backing up using wsl --export before uninstalling might be a good idea.

clxyder commented 1 year ago

I encountered this issue and removing the update fixed it, but ideally it would be awesome if we could fix this issue.

WSL:

Kernel version: 5.10.60.1

OS:

Edition Windows 10 Pro
Version 21H2
Installed on    ‎9/‎10/‎2020
OS build    19044.2846
Experience  Windows Feature Experience Pack 120.2212.4190.0
tvkit commented 1 year ago

On Windows 11. I disabled then reenabled (and rebooted) via Features which did nothing. Also tried the dsim recommendations to no avail. Upthread, someone mentioned the App Store. I found WSL there and Repaired it which worked. Existing containers okay.

nicholasq commented 1 year ago

a year and a half later after this issue was started and it's still not fixed

kendofriendo commented 1 year ago

+1 for what tvkit said. I did the "repair" option and it fixed it.

NotTheDr01ds commented 1 year ago

I believe this is a duplicate of #9231. Yes, technically 9231 is a duplicate of this, since it was created later, but it was the root-issue bug that the WSL team created publicly to track this.

This is now somewhat/mostly fixed in the 2.0.0 pre-release. Running:

C:\Program Files\WSL\wsl.exe

will now work from an SSH session (a.k.a. Session 0).

As mentioned in #9231, the WSL team is still working on enabling this for the "normal" wsl.exe binary.

xiaoc57 commented 10 months ago

我找到了适合我的解决方案:

  • 卸载“Windows Subsystem for Linux”(商店版本)
  • 通过命令行安装 WSL 请参阅 -> https://learn.microsoft.com/en-us/windows/wsl/install
  • 通过“wsl --update --inbox”更新 WSL 有了这个,我没有任何问题,并且可以通过 SSH 使用 WSL 中的所有功能。

very nice job

buvinghausen commented 10 months ago

Same thing cropped up with the 23H2 update. Was able to remove the WSL app and all components then bring it back to life from the command line.

xiaoc57 commented 9 months ago

我找到了适合我的解决方案:

  • 卸载“Windows Subsystem for Linux”(商店版本)
  • 通过命令行安装 WSL 请参阅 -> https://learn.microsoft.com/en-us/windows/wsl/install
  • 通过“wsl --update --inbox”更新 WSL 有了这个,我没有任何问题,并且可以通过 SSH 使用 WSL 中的所有功能。

非常好的工作

我找到了适合我的解决方案:

  • 卸载“Windows Subsystem for Linux”(商店版本)
  • 通过命令行安装 WSL 请参阅 -> https://learn.microsoft.com/en-us/windows/wsl/install
  • 通过“wsl --update --inbox”更新 WSL 有了这个,我没有任何问题,并且可以通过 SSH 使用 WSL 中的所有功能。

very nice job

if you want to use wsl whose version is app store, you should use ProxyJump, the command likes below: Host openssh_win32 Hostname 192.168.191.52 User xiaoc57

Host openssh_wsl ProxyJump openssh_win32 User xiaoc57 HostName localhost Port 2222 the openssh_win32 is your windows, and openssh_wsl may be your ubuntu. this command need start ssh in both operation system. and need listening 2222 from windows to wsl. maybe my describe is poor , if you have some question ,you can email me 2415777318c@gmail.com.

entee28 commented 7 months ago

My workaround worked as follows:

  1. Remove all subsystems and linux distributions from Apps and Features (aka Store installs)
  2. (Re-)install wsl using the steps for older versions of WSL

I wish you luck 🍀

Also confirming that this works for me, many thanks At the moment of this comment the wsl --install command will install the store version, which makes wsl in ssh session not working.

tgross35 commented 6 months ago

This appears to be fixed in a recent version 🎉. After running wsl --update from a GUI session, running wsl.exe in a SSH session correctly launches the Linux interface.

My version after the update is 2.0.14:

C:\Users\tg>wsl --version
WSL version: 2.0.14.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3155

Executing with the full path C:\Users\username\AppData\Local\Microsoft\WindowsApps\wsl.exe gets the same result, to confirm this is indeed using the Windows Store install.

mominshaikhdevs commented 6 months ago

This appears to be fixed in a recent version 🎉. After running wsl --update from a GUI session, running wsl.exe in a SSH session correctly launches the Linux interface.

My version after the update is 2.0.14:

C:\Users\tg>wsl --version
WSL version: 2.0.14.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3155

Executing with the full path C:\Users\username\AppData\Local\Microsoft\WindowsApps\wsl.exe gets the same result, to confirm this is indeed using the Windows Store install.

If you can launch the store version of wsl.exe(which is a msix-packaged command line executable) over SSH, Can you also verify that you are able to launch any other MSIX-packaged command line based executable over SSH too? For example: Julia?

tgross35 commented 6 months ago

If you can launch the store version of wsl.exe(which is a msix-packaged command line executable) over SSH, Can you also verify that you are able to launch any other MSIX-packaged command line based executable over SSH too? For example: Julia?

After running winget install julia -s msstore, I am indeed able to launch juliaup and julia over SSH, from the same location.

(I doubt it makes a difference but I am also using Powershell as the default shell for SSH, as described at https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration#configuring-the-default-shell-for-openssh-in-windows. Really that should be the default IMO)

mominshaikhdevs commented 6 months ago

After running winget install julia -s msstore, I am indeed able to launch juliaup and julia over SSH, from the same location.

wow! the root issue of all the other issues is https://github.com/PowerShell/Win32-OpenSSH/issues/1632 (which is basically, the MSIX-packaged executables that use App Execution Aliases[found in Settings > Apps > Apps & features > App Execution Aliases] inability to be launched over SSH).

seems, that root issue https://github.com/PowerShell/Win32-OpenSSH/issues/1632 has been fixed at last, which is good.

shihabsararrafid commented 6 months ago

On Windows 11. I disabled then reenabled (and rebooted) via Features which did nothing. Also tried the dsim recommendations to no avail. Upthread, someone mentioned the App Store. I found WSL there and Repaired it which worked. Existing containers okay.

Thanks a lot. It worked.

gtoal commented 4 months ago

I had the same problem on a Windows 10 system where uninstalling/reinstalling WSL2 was not an option (due to problems with X windows which only works under this one specific configuration). bash.exe would not run as would not also wsl.exe from \windows\system32, but the wsl.exe from Program Files\WSL at least started but failed because it didn't understand the "-c" parameter passed to it by ssh. So I made a workaround, which was to create a linux.bat file containing: @"c:\Program Files\WSL\wsl.exe" -- %2 %3 %4 %5 %6 %7 %8 and then setting the default ssh shell to that batch file via PowerShell in admin mode: New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "c:\ProgramData\ssh\linux.bat" -PropertyType String -Force The "--" in the batch file replaces the "-c" from ssh. I'm sure someone who knows Windows batch file syntax better than I can improve on that script, but at least I can now execute remote commands on my windows portable and get some benefit from that CPU... (The only thing remaining to be done to add this system to my small cluster is to mount my cluster's NFS file system in WSL2 - which is proving problematic, but that's a question for another forum and another day.)

robertoandrade commented 2 months ago

Just posted an answer on https://github.com/microsoft/WSL/issues/9197#issuecomment-2193873472 but perhaps should have commented on this since it's the only open ticket related to all duplicates including the ones mentioned in #11627 so quoting it here:

Had this very issue on a Windows 11 installation and after reading through all comments here I noticed that indeed the wsl.exe copies that get installed and are available on the standard PATH aren't really the actual executables, unless they get replaced or something gets changed after reboot/repair, but debugging through the instances of wsl.exe on the system:

>where wsl.exe
C:\Windows\System32\wsl.exe
C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps\wsl.exe

>dir C:\Windows\System32\wsl.exe
 Volume in drive C has no label.
 Volume Serial Number is 6E9D-788A

 Directory of C:\Windows\System32

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes
               0 Dir(s)  96,262,938,624 bytes free

>C:\Windows\System32\wsl.exe --version
The file cannot be accessed by the system.

Since while running dir /s \wsl.exe found many other copies in many directories including C:\Program Files\WSL\wsl.exe I ended up testing executing the same command with that one:

>"c:\Program Files\WSL\wsl.exe" --version
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.3155

That file seems to be much bigger than the ones on the path:

>dir /s wsl.exe
 Volume in drive C has no label.
 Volume Serial Number is 6E9D-788A

 Directory of C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.2.4.0_x64__8wekyb3d8bbwe

06/21/2024  07:55 PM         3,633,088 wsl.exe
               1 File(s)      3,633,088 bytes

 Directory of C:\Program Files\WSL

04/25/2024  06:19 PM         3,633,088 wsl.exe
               1 File(s)      3,633,088 bytes

 Directory of C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps

06/21/2024  07:56 PM                 0 wsl.exe
               1 File(s)              0 bytes

 Directory of C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe

06/21/2024  07:56 PM                 0 wsl.exe
               1 File(s)              0 bytes

 Directory of C:\Windows\System32

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6\f

02/09/2024  08:05 PM               344 wsl.exe
               1 File(s)            344 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6\r

02/25/2024  01:48 PM               595 wsl.exe
               1 File(s)            595 bytes

     Total Files Listed:
               8 File(s)      7,660,331 bytes
               0 Dir(s)  96,284,803,072 bytes free

So not sure if the other ones are stubs or some sort of "symbolic link" to the actual ones but they don't seem to work out of the box after installing and rebooting.

chandragie commented 1 month ago

On Windows 11. I disabled then reenabled (and rebooted) via Features which did nothing. Also tried the dsim recommendations to no avail. Upthread, someone mentioned the App Store. I found WSL there and Repaired it which worked. Existing containers okay.

realized that this thread is still active. this works for me 👍🏻 Thanks

buvinghausen commented 1 month ago

Happened again on my Surface Laptop 7 which is Snapdragon so it's a multi architecture feature ;-)