1832865 Members
2803 Online
110048 Solutions
New Discussion

Re: Confused about umask

 
SOLVED
Go to solution
Ed Hon
Regular Advisor

Confused about umask

By setting the umask, I want to set the default file mode for new files to -rwxr-xr--. However I'm now confused after doing the following experiment with the existing umask value:

# umask
00
# umask -S
u=rwx,g=rwx,o=rwx
# cd /tmp
# touch junk
# ll junk
-rw-rw-rw- 1 root sys 0 Jan 24 11:49 junk

Why aren't the permissions on junk
-rwxrwxrwx?

Thanks.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: Confused about umask

Even with a umask of 0, all FILES will be created with permissions of -rw-rw-rw-. Files are NEVER created with execute permission. That has to be added via the chmod command.

Directories on the other hand (try doing a mkdir junk) will be created with -rwxrwxrwx if your umask is 0. That is becuase execute has to be set on a directory to cd into it.
Helen French
Honored Contributor

Re: Confused about umask

Hi,

The files will be created with -rw-rw-rw permission only. But the directories will be created with rwxrwxrwx.

Check the man pages of umask, it will explian you in detail.

HTH,
Shiju
Life is a promise, fulfill it!
James A. Donovan
Honored Contributor

Re: Confused about umask

The default creation permissions are set to 666, your umask is set to 000. Therefore;

110 110 110 => default settings
000 000 000 => umask
--- --- --- => logical AND operation
110 110 110 => 666

a umask of 132 will yield the final permissions you say you want

110 110 110
001 011 010
--- --- ---
111 101 100 => 754 or -rwxr-xr--
Remember, wherever you go, there you are...
James A. Donovan
Honored Contributor

Re: Confused about umask

doh...nevermind...Patrick is correct..files are NOT created with execute permissions...


...just proves the point, never answer a question before your first cup of coffee
Remember, wherever you go, there you are...
oiram
Regular Advisor

Re: Confused about umask

Hi,

umask doesn??t set the default permission of a new file. The application is which should decide with which permissions should the file be created and the umask is used for making a logical AND operation between the permissions desired by the application and itself(man umask). For example if you make a tusc of the touch process you can see that this program use this system call

open("prueba_2", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) =

If you make man 2 open you can see the next information:

O_CREAT If the file exists, this flag has no effect,
except as noted under O_EXCL below. Otherwise,
the owner ID of the file is set to the effective
user ID of the process, the group ID of the file
is set to the effective group ID of the process i
the set-group-ID bit of the parent directory is
not set, or to the group ID of the parent
directory if the set-group-ID bit of the parent
directory is set.

The file access permission bits of the new file
mode are set to the value of mode, modified as
follows (see creat(2)):
+ For each bit set in the file mode creation mask
of the process, the corresponding bit in the
new file mode is cleared (see umask(2)).

+ The "save text image after execution" bit of
the new file mode is cleared. See chmod(2).

+ On systems with access control lists, three
base ACL entries are created corresponding to
the file access permissions (see acl(5)).

So the final permissions of a file are not only set by the umask value. The application should decide which permission need the file and the system should decide if that permissions are right or not.

Best regards.