chmod WSL (Bash) doesn't work

BashWindows 10ChmodWindows Subsystem-for-Linux

Bash Problem Overview


Running bash on windows 10, the simple syntax below works when I SSH to my webserver, but not when I exit out and am on my local machine. It doesn't give me an error, but I can see permissions are unchanged. I have to checked that I am set up as an administrator on my computer. Is this an error or is this just a consequence of the local operating system being windows? IF the later, it makes me question the value of using bash on windows if common operations such as this won't work.

$chmod 644 filename 

Bash Solutions


Solution 1 - Bash

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) 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

Solution 2 - Bash

There was an update to WSL recently (source), which lets you change permissions to files (Insider Build 17063).

All you have to do is to run:

sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata

Solution 3 - Bash

Both Amades and Chaos answers are correct. But it only works for local drives not for mapped network drives. Z: is one of my network drives. Same operation on /mnt/c/Users/xxx/ works fine.

$sudo mount -t drvfs Z: /mnt/z -o metadata
$touch test
$chmod +w test
 chmod: changing permissions of 'test': Operation not permitted

This is a known issue, see drvfs: metadata (chmod\chown) possible for mounted SMB drives?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjoe5View Question on Stackoverflow
Solution 1 - BashChaoView Answer on Stackoverflow
Solution 2 - BashAmadeView Answer on Stackoverflow
Solution 3 - BashhkoView Answer on Stackoverflow