Monday, 1 June 2015

Unix: Default permissions on files and folders

First of all let's get familiar with the 3 levels of permission and their octal representation in Unix:

read:         100 (4 in decimal)
write:        010 (2 in decimal)
execute:    001 (1 in decimal)

Therefore,
only read => 4
read/write => 6
read/write/execute => 7


Now, in Unix, if we run the following command:
umask
we'll find the output as 0022
The first '0' says that's it's an octal number and '022' represents the mask to be applied.

Let's see how it get's applied to set default permission on files and folders in Unix.

Files:
====
Initial permission after file creation: 666 (read/write for owner, owner's group and others)
Now,
666-022 = 644 happens
leading to =>
for owner                  : 6 (read/write/execute)
for owner's group     : 4 (read)
for others                  : 4 (read)


Folders:
======
Initial permission after folder creation: 777 (read/write/execute for owner, owner's group and others)
Now,
777-022 = 755 happens
leading to =>
for owner                   : 7 (read/write/execute)
for owner's group      : 5 (read/execute)
for others                   : 5 (read/execute)


No comments:

Post a Comment