This is on a test machine, not production. I included the following in a user's .bashrc:

umask 000

I relogged in. When I go to create a file in my home directory, say using vi test.txt, the file gets permission rw-rw-rw.

I also tried setting umask manually:

umask a=rwx

What am I doing wrong, as I need the equivalent of CHMOD 0777 or 0755 on files and directories? Again, this is a test situation, so security is of no concern at the moment.

Edit: Come to think of it, is this impossible? Since umask for files gets subtracted for 666, lowest umask is 000, therefore, CHMOD of 666 is the highest a file can get? There's no way to give files CHMOD of 755 or 777 using umask?

  • What output do you get for cd /tmp ; rm -f masktest; umask 000; touch masktest ; ls -l masktest?
    – Zoredache
    Jun 27 '11 at 20:25
  • -rw-rw-rw- ....
    – djdy
    Jun 27 '11 at 20:27

I can't find a reference but I'm fairly sure that you can't set x as a default permission on a file.

  • Possibly as security measure, you do not want files to be executable by default. Since the umask also applies to directory creation which needs the execute bit for allowing users to descend into it, it makes sense for not requiring umask 133 to prevent the execute bit from being set on files.
    – Lekensteyn
    Jun 27 '11 at 20:36
  • 1
    The umask doesn't set default permissions, it masks them. It's up to the code calling open() with O_CREATE to set the executable bits or not.
    – JimB
    Jun 27 '11 at 20:43
  • @Lekensteyn: Yup - I would expct that to be the case.
    – user9517
    Jun 27 '11 at 20:44

umask doesn't set the default permissions, it's used to modify the default mode of certain system calls, like, open(2) and mkdir(2).

In your case, vim is creating the file with a mode of 0666, which would be further modified by the umask. The default of 0022, would then create a file with a mode of 0644. The umask can't add bits, it can only mask them (hence the name).

As an example, executing

$ touch testfile
$ ls -l testfile
-rw-r--r-- 1 bob bob 0 2011-06-27 16:36 testfile

yet it made the following system call (notice the 0666 in the mode_t field)

open("testfile", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.