WSL’s default file system options are not the best when working with UNIX tools. To fix them, do the following:
Add the following to
/etc/wsl.confin your WSL distribution:
Check your umask setting by running
umaskin WSL. If it’s
0000, you’ll need to add
~/.profile. This can be done by running
echo "umask 022" >> ~/.profileto add it to the end of the file.
Close all instances of WSL then run
wsl -t distribution_namereplacing
distribution_namewith the name of your distribution. To get a list of them, run
automount options in
/etc/wsl.conf specify the mount options for DrvFs
which allows accessing Windows files from WSL. These changes do the following:
chowndon’t work with Windows partitions (eg.
/mnt/c) by default in WSL. Adding the
metadataoption fixes this.
Files in DrvFs are not case-sensitive by default (
case=dircauses any new directory created in WSL and all its contents to be case-sensitive. This is important for programs like Git which will not detect case-sensitive renames properly without this option.
By default, all files and directories in DrvFs have 777 permissions. That is, they are readable, writable, and executable by everyone. Adding the
umask=22(same as 022) option masks (turns off) the write permission (i.e. the second bit which is equal to 2) for everyone but the owner, making all files and directories have 755 permissions. Adding
fmask=111further masks those permissions for files specifically, turning off the execute bit (i.e. the first bit) for everyone, bringing file permissions down to 644. Having the correct permissions is also important for Git which will commit files with an executable bit as such.
While the automount options will affect files in DrvFs, they have no effect on
files created in the regular filesystem. There, the default permissions are 777
for directories and 666 for files. These are then modified by a system umask.
In current versions of Windows 10, the system umask is not
applied resulting in a umask of
0, giving everyone write permissions. Setting a umask of 022 in the shell’s
~/.profile fixes this.