Search code examples
linuxfileunixumask

Umask In open() Syscall?


While reading about open syscall and in more details the parameters we send, I read:

The umask acts as a set of permissions that applications cannot set on files. It's a file mode creation mask for processes and cannot be set for directories itself. Most applications would not create files with execute permissions set, so they would have a default of 666, which is then modified by the umask. As you have set the umask to remove the read/write bits for the owner and the read bits for others, a default such as 777 in applications would result in the file permissions being 133. This would mean that you (and others) could execute the file, and others would be able to write to it. If you want to make files not be read/write/execute by anyone but the owner, you should use a umask like 077 to turn off those permissions for the group & others. In contrast, a umask of 000 will make newly created directories readable, writable and descendible for everyone (the permissions will be 777). Such a umask is highly insecure and you should never set the umask to 000. The default umask on Ubuntu is 022 which means that newly created files are readable by everyone, but only writable by the owner.

Can someone kindly explain what is this mask in general? I never heard of it before?


Solution

  • The umask value determinants the permissions given to a file when is created, the default permissions given to a file, after is created you can change it with chmod.

    If you want to check the value setting, you have to execute the command “umask”, this could tell you the value as default that the user has to create files.

    If you want to change the umask value you can run the following command to set it.

    umask 022

    Keep in mind that the numbers that are you described in the command above are the permissions that won't give to the file, so, in this case, will be generated with 755.