To enable changing file owners & permissions, you need to edit /etc/wsl.conf
and insert the below config options:
[automount]
options = "metadata"
Do this inside the WSL shell, potentially needing sudo
to edit/create the file.
This may require restarting WSL (such as with wsl --shutdown
which is a Windows command, not one within WSL) or the host machine to take effect. This has been possible since 2018:
You can now set the owner and group of files using chmod/chown and modify read/write/execute permissions in WSL. You can also create special files like fifos, unix sockets, and device files. We’re introducing new mounting options with DrvFs for projecting permissions onto files alongside providing new Linux metadata on files and folders.
[cite: Microsoft Dev Blog]
You can also temporarily re-mount a drive with the following commands:
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
...but please note, the command only takes effect in session scope. If you exit current bash, you'll lose your settings (credit: answerer Amade).
Reference:
Automatically Configuring WSL
chmod 555 filename
. Implicitly everyone will always have read and execute access, since no Windows file attributes correspond to that. – HexosanPATHEXT
extensions, and it controls the read-only flag only via the user permissions instead of requiring it unanimously for user, group, and other. – Hexosansudo
? – Expectingchmod
work as well as can be expected. Native Linux filesystem support is provided by the lxfs filesystem used for "/", which is persisted to disk in the user's%LocalAppData%\lxss
folder, but not for use in Windows. – Hexosan