Tuesday, January 19, 2010

Permissions and Umask

लिनक्स संबंधी सभी डाउन लॉड्‍स के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:

chmod


As shown in the output of ls -l command above, each and every file has the permissions associated with it. These permissions are defined for three types of persons namely- the owner of the file, the group members of the owner, and all other persons who are not the members of the group whom this owner belongs to. Let us have a look on following line:


-rwxrw-r-- 1 root root 468 Aug 8 07:15 file1


Permissions are defined within first ten characters of the above like output from ls -l. Normally, the first character can either be - or d, - represents that it is a file while d represents a directory. Remaining characters are grouped in set of three characters which are r (read), w (write), and x (execute).


In the above example first three characters are rwx which means owner of the file has all the permissions on file1. Next three characters are rw- which will mean the group members will have read and write permission on file1 but not execute permission on it. The last set is r—which will mean that others will only have read permission on file1 but they will not have write and execute permission on file1.


We can set the permissions by using chmod command. For example, for setting the permissions as above we can run the following command:


# chmod 764 file1


We can use the following example to find any type of permission, we want to set.



umask


When new files or directories are created, they get some default permissions. These permissions depend on value of umask. This command when used alone will show the current numeric masked value of the permissions. This is as under:


# umask

0022


Here we should remember that first number is not currently in use, therefore, the actual mask will be 022 in the above example. We should remember that, by default, execute permissions are off for regular files, i.e. we can not assign x permission by umask. Hence, umask value masks the permission value of 666 for a file and 777 for a directory.


1. For finding the desired umask value for files, we will see the following examples:


Desired permission r w - r - - r - -

Binary equivalent 4 2 0 4 0 0 4 0 0

i.e. 6 4 4


umask value 6 - 6 6 - 4 6 - 4 (for file umask always subtract from 6)

i.e. 0 2 2 (so the actual umask will be 022)


2. For finding the desired umask value for directory, we will see the following examples:


Desired permission r w x r - x r - x

Binary equivalent 4 2 1 4 0 1 4 0 1

i.e. 7 5 5


umask value 7 - 7 7 - 5 7 - 5 (for file umask always subtract from 6)

i.e. 0 2 2 (so the actual umask will be 022)


Hence, we saw that umask value 022 will result in default permissions of rw-r--r-- for file and of rwxr-xr-x for directory.

1 comment: