WSL: wsl.exe fails with "Access is denied"

After uninstalling an re-installing Windows Subsystem for Linux I can’t install any distro - they all fail with “Access is denied”. Even running wsl.exe now fails with “Access is denied”.

Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.18362.657]

Steps to reproduce

> wsl.exe Access is denied

Strace and logs attached.

wsl_strace.txt

logs.zip

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 26
  • Comments: 74

Most upvoted comments

Had the same issue when running as admin, when running without it WSL works fine. try it.

After uninstalling KB4565503, updates automatically install it again. Is there a permanent fix for this issue?

Yes - grant your user account full control over the .vhdx file. See https://answers.microsoft.com/en-us/windows/forum/all/kb4565503-installed-then-wsl-2-failed-to-start/25794c4f-0b20-465e-bbdb-a8af3d9e0e88

Fixed after running the following in PowerShell as administrator

Add-MpPreference -AttackSurfaceReductionOnlyExclusions "C:\windows\system32\wsl.exe"

Add-MpPreference -AttackSurfaceReductionOnlyExclusions "C:\Program Files\WSL\wsl.exe"

If anyone are facing this problem, check if you have an App called Windows Subsystem for Linux, if yes, uninstall it and you will get access to wsl2 again.

It was installed here after running wsl --update command.

image

I have the same issue on an Ubuntu installation imported from a TAR file to a custom location. I already have access to the WindowsApps folder; this doesn’t help.

Running as a regular user: I get the “Access Denied” message when trying to start wsl.exe. Running as Administrator": wsl.exe works to .start the distro running. I can then use it either as admin or as a regular user (via wsl.exe, Windows Terminal, VS Code…) However, if the distro shuts down (e.g. via wsl.exe --shutdown), then I lose my ability to connect as a regular user, and have to run wsl.exe as admin again.

Problem seems to have appeared with Windows Update KB4565503 earlier this week.

EDIT: After uninstalling KB4565503, the problem disappears.

If anyone are facing this problem, check if you have an App called Windows Subsystem for Linux, if yes, uninstall it and you will get access to wsl2 again.

It was installed here after running wsl --update command.

image

amazing. simply amazing. so wsl.exe --update takes away the possibility to use wsl.exe command line. thus for example completely breaking Docker.

how could this ever have slipped through Microsoft’s quality control?! and it’s been this way since at least 8 months?!

Same over here.

Switched from WSL 1 to WSL 2. After rebooting I got an Access is denied. Later I found that I didn’t have Windows Version 2004, Build 19041 install but only 1909 Build 18363.720.

So I removed WSL from Windows Features, reboot, and activated WSL again with the effect that I get an “Access is denied” in PS being Admin but runs without Admin. However, I’m stuck now since I can no longer use wsl.exe being Admin nor revert to any previous state.

I seem to ahve the same issue… Although I can start ubuntu when I open it from the store, executing wsl always results in " Access is denied".

So during not even a full year, Microsoft was able to completely break Docker via WSL two times via bodged updates - creating a massive amount of wasted working hours and annoyance. 👏🏼🤡

This appears to be due to a windows update causing WSL.exe to trigger an attack surface reduction rule in defender for endpoint.

https://learn.microsoft.com/en-us/defender-endpoint/attack-surface-reduction-rules-deployment-test#step-2-understand-the-attack-surface-reduction-rules-reporting-page-in-the-microsoft-defender-portal - Your IT admins can use this report to see if wsl.exe is triggering the rule.

We confirmed this was the issue for our users after installing the latest updates pushed on 08.13.

From here we went into the intune ASR policy and set an exemption for WSL.exe (decent write up here, this is not our page - https://www.nielskok.tech/microsoft-defender-for-endpoint/add-exclusion-in-attack-surface-reduction-microsoft-defender-for-endpoint/)

We tested by running gpupdate /force on impacted devices and rebooting. After reboot, we were able to resume normal ops.

I suddenly had this problem. I have been working using an administered laptop and have been using WSL Ubuntu for work environment. Laptop went to sleep and when turned on VSCode and cmd couldn’t access WSL.

image

image

image

Issue #5605 has a possible “permanent” fix for the issue triggered by KB4565503.

Also got past this with WindowsApps folder permissions. You need to change the owner of this folder so you can get access to it. Try this link (ignoring the stupid download an app version 1 of course 😃 https://www.maketecheasier.com/access-windowsapps-folder-windows-10/

Also having this issue and adding these rules to powershell in admin mode still gives me an access denied when trying to launch wsl. Any other alternatives?

If you are using intune to manage these devices your intune admin will need to go into the attack surface reduction rules and exempt WSL from there then you can run a group policy update and reboot.

You may be able to look at the windows protection history and see if this is the case:

image

https://github.com/microsoft/WSL/issues/4920#issuecomment-2291906640

Same here, seemed to happen after installing the latest Windows Updates:

  • 2024-08 Cumulative Update for .NET Framework 3.5 and 4.8.1 for Windows 11, version 24H2 for x64 (KB5042098)
  • 2024-08 Cumulative Update for Windows 11 Version 24H2 for x64-based Systems (KB5041571)

@vncntk Seconding this, the exact same thing happened to me today as well. Have not found a solution yet either.

I too have this issue but in my case, McAfee endpoint security is installed on my machine and it is blocking me to run it. In the McAfee endpoint security, the below message was posted. The windows update KB4565503 is NOT installed on my machine.

[MyUsername] ran C:\Windows\System32\wsl.exe, which attempted to access the process LxssManagerProxyStub.dll, violating the rule “Executing Windows Subsystem for Linux”, and was blocked. For information about how to respond to this event, see KB85494.

I found the resolution from the below source. Source: answers.microsoft.com

I experienced this issue when Docker stopped unexpectedly.

PowerShell would either return that I didn’t have permission (when run outside Administrator) or Access Denied (when run as Administrator. In a command prompt I was getting Access Denied when trying to run wsl, but was still able to run wsl --help.

If you are able to run wsl --help and get information back, you should be able to do the following:

  1. Run wsl --list --verbose to get a list of distros
  2. wsl --shutdown
  3. wsl --unregister [distro name listed from step 1]

Then I had located ext4.vhdx and deleted the folders in AppData that contained this file (Mine was Docker). If you can’t delete it because it says it is open in System, restart and you should be able to delete it. After it’s deleted, you should have access to wsl in PowerShell and cmd and be able to reinstall the distro you deleted.

Same here. Just updated Win 10 yesterday and now my WSL2 throws “Access denied” but if you run terminal as administrator and then go to wsl, it works.

Can confirm the specific update (KB4565503) was the issue. wsl now works perfectly and doesn’t say access denied.

I have the same problem. I followed these steps https://docs.microsoft.com/pt-br/windows/wsl/install-win10 And got stucked in the part I had to switch to version 2. I can’t simply run wsl because windwos always say Access Denied

Same for me, the solution provided by @dylancarruthers solved the issue when in Administrator mode. Docker Desktop also stopped working because of this and resolved that by:

  1. Stopping Docker Desktop
  2. Run wsl --unregister docker-desktop
  3. Restart Docker Desktop

If you have WSL “Access is denied” problem, at first check where have you your WSL installed. If you use WSL from Microsoft Store (it is good choice, because you have got fresh and current version) then WSL is installed in C:\Program Files\WindowsApps\ folder. And this folder has very limited access. Local administrators can’t access this folder. I took over ownership of files in this directory to LOCAL-DOMAIN\Administrators. Then it was possible to add Read/Execute rights to LOCAL-DOMAIN\Administrators. After it WSL start working via SSH or other remote access.

I started recently getting File permission errors when trying to edit anything under \\wsl$\Ubuntu-20.04 from Windows Explorer, opening in VSCode. In the end I resorted to unregistering from Powershell (wsl --shutdown and wsl --unregister Ubuntu-20.04), and then re-installing (I just clicked on the Ubuntu icon which I had pinned in the taskbar, and it reinstalled). After reinstalling and creating the new user, now I can access and edit files using Windows Explorer and VSCode.

Unfortunately this has the downside of removing all data within the Ubuntu instance. It seems to me to be a pretty drastic approach. I had already checked permissions on the ext4.vhdx file (C:\%USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx) and they were all correct as far as I could tell.

I have the same problem, but the only update I installed was:

* 2024-08 Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.417.101.0)

@koleh-tech Defender was the cause for us too with this rule: Block use of copied or impersonated system tools. If you can check your protection history in Defender you might see all the blocked wsl.exe actions.

For anyone who might still be stuck here, this solution worked for me:

Quoting from that solution: wsl --unregister ubuntu followed by wsl --install fixes the problem for ubuntu atleast

Had simillar problem. Running as administator won’t help. (Access Denied) After some manipulations, I’ve decided to turn off Windows Update Blocker (wub)

Now, WSL works

I just fixed it. wsl --import Ub C:\Users\fs\wsl\Ub C:\Users\fs\backup\wsl\wsl.tar.gz --version 2 worked, whereas wsl --import Ub C:\Users\fs\wsl\Ub C:\Users\fs\backup\wsl\wsl.tar --version 2 failed. I don’t know why I decided to unpack the gz file in the first attempt and tried to import from there.

In my case, windows permission mixed up with linux permissions, and disabled the x attribute on my folders, so I couldn’t read them.

I had to do

chmod +x folder

I had already installed Ubuntu on my machine a while ago. Today I found I could not start it:

i. Trying to click “Ubuntu” in the Start Menu would appear to not react, ii. trying to start it from cmd.exe would exit immediately.

What did work, was to start cmd.exe or powershell.exe as Administrator and run wsl from there:

C:\Windows\system32> wsl
root@DESKTOP-XXXXX:~# uname -a
Linux DESKTOP-XXXX 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
root@DESKTOP-XXXXX:~# logout

I tried to reinstall:

PS C:\Windows\system32> # this is in powershell
PS C:\Windows\system32> cd C:\Users\user
PS C:\Users\user> Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing
PS C:\Users\user> Add-ProvisionedAppxPackage -PackagePath .\Ubuntu.appx -Online -SkipLicense

It appeared to install successfully, however I still had the same symptoms.

I tried reinstalling again, this time directly in my user account:

PS C:\Users\user> Get-AppxPackage -name CanonicalGroupLimited.Ubuntu18.04onWindows | Remove-AppxPackage
PS C:\Users\user> Add-AddxPackage .\Ubuntu1804.appx

It didn’t solve it, but instead of Ubuntu crashing immediately, it told me:

PS C:\Users\user> ubuntu1804.exe
Access is denied.

(which is what brought me to this thread)

but it still works as Administrator.

@jwsinner’s fix in https://github.com/microsoft/WSL/issues/4920#issuecomment-746843348 seems to have actually fixed it fully! And done it without having to garble my system permissions or anything:

In my Administrator shell:

PS C:\Windows\system32> wsl --list --verbose
  NAME		STATE		VERSION
* Ubuntu-18.04	Running		1
PS C:\Windows\system32> wsl --shutdown
PS C:\Windows\system32> wsl --unregister Ubuntu-18.04
Unregistering...
PS C:\Windows\system32> 

Then, as my regular user, without reinstalling anything package:

PS C:\Users\user> ubuntu1804.exe
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:

I’m -1 on KB4565503 being the problem. I don’t have it installed:

2021-03-20-162400_896x645_scrot

I have Windows 10 Pro N-1909-18363.1440:

2021-03-20-163231_457x280_scrot

~@codemonkey33 has the solution that worked just fine for me. I still had the problem even when I had imported my ubuntu outside of the WindowsApps folder, weird…~

EDIT: @rosea-tf has pinpointed the bug below. It only happens once wsl is shutdown by itself. You’ll have to access wsl as admin and then you’ll have access again.