WSL: Default umask (permissions) is not applied

Reference: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

My current install has this in /etc/profile:

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

And, indeed /etc/profile has UMASK> > 022, but:

simon@QOF:~$ umask
0000

The effect of this is that new files are created with 666 and dirs with 777 permissions:

simon@QOF:~$ touch file
simon@QOF:~$ mkdir dir
simon@QOF:~$ ll -d file dir
drwxrwxrwx 2 simon simon 0 May 12 22:54 dir/
-rw-rw-rw- 1 simon simon 0 May 12 22:54 file

This mostly isn’t a real problem since UoW doesn’t have to care about multiple users, it largely shows up as ls showing dirs with an ugly green background, but it could freak out some tools, similar to ssh wanting 600 on your private keys.

Simplest fix would probably be to dump a umask 022 in /etc/profile, but it seems there’s a bunch of stuff in that /etc/login.defs

Easy workaound is to add a umask to your ~/.bashrc

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 46
  • Comments: 37 (4 by maintainers)

Commits related to this issue

Most upvoted comments

The current behavior is expected. We will be reevaluating where umask gets set in an future release.

@jackchammons Why was this closed? Until the umask is working out of the box, this issue is still ongoing.

Please ensure umask is never 0000 no matter how bash is started.

I understand users can set umask to saner defaults in their own bashrc files but it means whatever directories and files auto-installed by scripts after WSL setup and user first bash run till the bad umask was discovered now have to be changed to sane defaults. This is exacerbated in git-based repos because git will track the change of perms to saner defaults as a (needless) change thereby status of git repo becomes dirty which simply put is both: confusing and annoying.

I have put this in my ~/.profile in the meantime:

# Note: Bash on Windows does not currently apply umask properly.
if [ "$(umask)" = "0000" ]; then
>   umask 022
fi

@benhillis: if you have time to entertain my curiosity - is there a particular reason you don’t run /bin/login?

Woo! My ls will finally be cured of it’s horrifying green miasma!

Thanks for your patience. I’m adding a default umask of 022, with an /etc/wsl.conf setting to override it:

[filesystem]
umask = 02

This issue is causing trouble when running the Linuxbrew/Homebrew package manager in WSL. I’d love to see the default umask set to 002.

@lilred - good question. Historically there have been a couple of reasons. When we first released /bin/bash worked but other shells (zsh for example) didn’t work very well and we didn’t want users to set their default shell to something that didn’t work and get into a bad state. There’s also potential strangeness around running bash.exe and zsh being launched.

That being said, running login would actually make a lot of things simpler for us.  Currently our init daemon has to do many of the things that /bin/login normally does. We’re doing some design for the next release of Windows and I’ll take a look at this and see if it would make sense to potentially switch things over now.

If you’d like to play around with using login there’s a way you can use it now.

lxrun.exe /setdefaultuser root bash.exe -c “/bin/login -f username”

I just updated to 1909 and this problem is still there.

This is still a thing? Is 3 years not long enough to arrive at a conclusion to this issue?

I really can’t see this being a “feature” 😟

I just updated to 1909 and this problem is still there.

Right; it looks like Ben’s fix shipped in 18945. 18945 > 18363 (aka 1909 aka 19H2). Which is to say, it appears a number of issues that were addressed in spring/summer 2019 never made it into the November 2019 Windows 10 release. [Or, at least on best evidence.] I’ll bounce the tag on this one, but to be honest I’m hoping the fine-grained fixed-in tags die this spring in favour of whatever version is cited in the issue (presupposing they’re cited). Here, 18945.

This is how I workaround it in my dotfiles, if it helps anyone 😉

This is breaking unit tests for swift-llbuild, part of the Swift.org project:

$ umask 22 $ umask 0022 $ mkdir foo $ ls -l drwxrwxrwx 2 root root 0 Mar 23 16:47 foo

With /bin/login I do get umask returning 002, which is probably “good enough” to close this, but it’s still not getting the “correct” default value 022 from /etc/login.defs line 151, which may be a thing.

Also it seems to start faster?!

/usr/bin/m4: m4_esyscmd subprocess failed: Operation not permitted /usr/bin/m4:configure.ac:489: cannot run command `./scripts/version.sh’: Operation not permitted

May be somewhat related to #167 , /etc/profile is supposed to be read if bash is a login shell - but even bash.exe --login doesn’t seem to use pam_umask