WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Permission Denied when writing to \\wsl$\... path even from elevated shell [wsl2]

Open ejohb opened this issue 7 years ago • 6 comments

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      18990  0


PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> wsl --list --verbose
  NAME            STATE           VERSION
* test            Running         2

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> cp C:\wsl.conf etc/wsl.conf
cp : Access to the path '\\wsl$\test\etc\wsl.conf' is denied.
At line:1 char:1
+ cp C:\wsl.conf etc/wsl.conf
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\wsl.conf:FileInfo) [Copy-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand

There doesn't seem to be a way to modify the files from the Windows side. Is this a bug?

ejohb avatar Nov 02 '19 12:11 ejohb

Maybe a feature: accessing \\wsl$ seems to obey permissions from the Linux side.

karuboniru avatar Nov 03 '19 05:11 karuboniru

Maybe a feature: accessing \wsl$ seems to obey permissions from the Linux side.

Ah! Yeah now I understand what it's doing (using the default Linux user permissions), thanks. Changing the default user to root indeed works.

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> set_default_user test root
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> wslconfig.exe /t test
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> set_default_user testroot
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\test> cp C:\wsl.conf .\etc\wsl.conf

Even so, that's a bit inconvenient. It means I need to kill the WSL instance entirely (cos changing the default user doesn't work otherwise) if I want to do anything that needs root. I would say that an elevated Windows environment should implicitly have root via P9.

ejohb avatar Nov 03 '19 12:11 ejohb

We need a configuration option where "wsl$" ignores ownership and permissions; but preserves those attributes when a file is changed.

I tried running notepad pluss "as admin" and then try to update an /etc file; BUT I could not get it to work

stevebovy avatar Nov 04 '19 04:11 stevebovy

"wsl$" is an excellent and wonderful new feature, but as always with everything LINUX, esoteric concerns for necessary compatibility gets in the way of practical functionality and usefulness.

OF COURSE we must absolutely preserve ownership and permissions for the sake of compatibility and for the sake of proper usage and proper testing.

BUT when a windows machine is a private dev working machine ; I hope we can try to avoid tripping over our own shoelaces.

Practical usefulness predicates that we must try to find a way to work around this short sighted built-in limitation.

After-all ON Linux 20-30% of most file-management activity is ADMINISTRATIVE and not work related productivity ( so this limitation that we are disusing ) puts a huge damper on the effective usefulness of this new feature.

Thanks again for the great work. But Please do not put UN-needed and unnecessary HAND-CUFFS ON THIS NEW FEATURE. !!

stevebovy avatar Nov 04 '19 08:11 stevebovy

This file permission issue manifests itself in many ways. For embedded Linux development, the ability to run and configure Yocto and Buildroot is mandatory. Unfortunately neither build tool completes due to inexplicable file permission errors. Doing exactly the same on Mint19.3 completes with no issues. I have tried the metadata options to no avail. I'm afraid that wsl2 is anon-starter for Embedded Linux devs on Win10. Too bad because wsl2 is great in other ways.

edsyl avatar Apr 19 '20 18:04 edsyl

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!