Understanding umask

Default file and folder permissions are set by the umask program. The umask command without any argument will display the existing value of umask. The same command, when followed by a new octal value as an argument, will set the new value of umask. The following command line is used to view the existing umask of a user:

$ umask

Normal users have a different umask,and the root has a different umask value, to decide the default permissions for files and directories. The following examples illustrate the different umask values the exit in system for a regular user and a root user:

  • Execute the umask command on Terminal as a root user to view the umask value for the root account, as shown in the following screenshot:

  • To view the umask value of student user, first switch to student user account and then execute the umask command as shown in the following screenshot:

For files, the maximum default value is generally 666 (normal files do not require execute permissions to be set by default), and for directories the maximum default value is 777 (since directories require execute permissions to be set using the cd command). The umask values are taken off from the maximum default octal values to decide the default permissions for files and directories.

For example, let's understand the umask value 0022 that is the default value of the root account. It means remove write permissions for the group and others from the maximum permissions of files and directories. Hence, the default permission for the file will be 644, and for the directory it will be 755. Similarly, a umask value of 0002 that is the default value of the normal user account, means remove write permissions for others from the maximum permissions of files and directories. Hence, the default permission for the file will be 664,and for the directory it will be 775.

While setting a new umask value of user, if the argument of umask command contains fewer than three octal digits, then leading zeros are assumed in the argument part.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.50.87