A What is Umask?
when we log into the system and create a file that always has a default permission, how does this permission come from? That's what Umask did. Umask set the user to create the default permissions of the file, it is the opposite of chmod effect, Umask set the right "complement", and chmod set the file permission code. You typically set the Umask value in/etc/profile, $ [Home]/.bash_profile, or $[home]/.profile.
Your system administrator must set a reasonable umask value for you to ensure that the file you create has the desired default permissions to prevent other non-identical users from having write access to your files. After you have logged in, you can use the umask command to change the default permissions for file creation according to your personal preferences. The corresponding change is valid until you exit the shell or use a different umask command. In general, the Umask command is set in the/etc/profile file, which is referenced by each user at login, so if you want to change the umask of all users, you can include the corresponding entry in the file. If you want to permanently set your own umask value, place it in a. Profile or. bash_profile file in your own $home directory.
b How to calculate the Umask value
umask command allows you to set the default mode of file creation, corresponding to each type of user (file owner, same group of users, other users) there is a corresponding number in the Umask value. For a file, the maximum value for this number is 6, respectively. The system does not allow you to give it permission to create a text file, and you must add this permission with the chmod command after creation. The directory allows you to set execution permissions, so that for the directory, the number of umask can be up to 7.
For example, for the Umask value 0 0 2, what are the corresponding file and directory default creation permissions?
In the first step, we first write a pattern with full permissions, that is, 777 (all users have read, write, and Execute permissions).
In the second step, the following line writes the corresponding bit according to the Umask value, which in this case is 0 0 2.
The third step is to make a note in the next line that there are no matching bits in the above two lines.
This is the default creation permission for the directory.
The fourth step, for the file, at the time of creation can not have execute permission, just take out the corresponding execution permission bit.
This is the example above, where u m a s K value is 0 0 2:
1) file with maximum permissions rwx rwx rwx (777).
2) umask value 0 0 2-------w
3) directory Permissions rwx rwx r-x (775) This is the directory creation default permission.
4) file Permissions rw-rw-r--(664) This is the file creation default permission.
This article is from the "technology Change the Future" blog, please be sure to keep this source http://zx953.blog.51cto.com/1619047/1747785
Linux under Umask detailed