how umask works

Lately I have seen quite a few posts on umask and its usage. Avery good explanation of what umask does was provided by Lew pitcher here.

I checked wikipedia since I could not believe that the original poster did not find the answer there. After 5 lines I realized that there was no real explanation in this article :-(.

So here is a summary/explanation/rationale of what umask do and why:

  • umask allow a user to control how files are created on his system
  • umask use an octal numbering scheme hence, umask permission starts with ‘0’ e.g. 0022
  • umask tell the system what permissions on file you want to disallow (this is the source of confusion)

If a random program wants to create a file on your home directory with permissions 0777 (i.e. read, write, execute for you, the group and everybody else), you would like to have the possibility to refrain it to do so by setting which permission you want to disallow: this is your home directory and you don’t want a silly to do whatever it wants !

A umask of 0022 means “I don’t want any file on my system to be created with write permissions for the group, and without the write permissions for the others.

In the case of an umask of 0022:

  • first digit is always zero, so that the umask is read as an octal number
  • second digit describes the owner rights to disallow
  • third digit describes the group rights to disallow
  • forth digit describes the others rights to disallow

The value to setup the permission value is the sum of: 4 for read, 2 for write and 1 for execute.

The umask is your file creation policy acting as a permissions filter.

Enjoy and share.

Advertisements

About this entry