Introduction to LinuxUmask

Source: Internet
Author: User
A permission mask umaskumask is supported by chmod and has a total of four bits (gid/uid, owner, Group permission, and permissions of other users). However, the last three bits are usually used, for example, if you use chmod755file (the permission for this file is Master read (4) + WRITE (2) + execute (1), the same group and other users have read...

A permission mask umask
Umask is supported by chmod. it has a total of four bits (gid/uid, owner, Group permission, and permissions of other users), but the last three are usually used, for example, if you use chmod 755 file (the permission for this file is Master read (4) + WRITE (2) + execute (1), the same group and other users have read and write permissions)
Role of binary umask
By default, the umask value is 022 (which can be viewed using the umask command). The default permission for the created file is 644 (6---2 ), the default permission for the created directory is 755 (7---2). you can use ls-l to verify it. now you should know the usage of umask, it is used to control the default permissions. do not assign full permissions to the default files and directories.
3. modify umask value
After learning about the role of umask, you can modify the value of umask. for example, umask 024 will grant the default permission to files and directories created later to 642,753.
IV. Save the umask value to the environment file
If bash is used, you can change umask in the/etc/bashrc file. if csh is used, you can change/etc/csh. cshrc.
Do you know what the default attribute is when you create a new file or directory? Haha! This is related to umask! So what is umask? Basically, umask is to specify the "default attribute value of the current user when creating a file or directory". how can we know or set umask? Its specified conditions are specified in the following way: syntax:
[Root @ test root] # umask
0022
[Root @ vbird test] # umask 002 <== followed by three numbers!
[Root @ vbird test] # umask
0002
Note: Check whether the umask value can be set by directly inputting umask? That's right! It is umask followed by three numbers! How can we specify it? It is mainly related to the file attributes of Linux (the nine attributes, r, w, x), and the relationship of scores is used as an example, supplemented by the following rules:
If the user creates an archive, the default "no executable (x) project" is created, that is, only rw projects, that is, up to 666 points.
-Rw-
If the user creates a "directory", x is enabled for all permissions, that is, 777 points, because x is related to whether the user can access this directory.
Drwxrwxrwx
 
Then umask specifies the "permission to be removed for this default value !』 Because r, w, and x are 4, 2, and 1 points, so ?? Will the notebook fade? Currency? Meiyun benzna? If you want to get the read and write permissions, that is, the read and write permissions should be removed, but the execution and write permissions should be removed, that is, 3 points. do you know this? Excuse me, what is 5 points? Haha! Read and execute permissions! As described in the preceding example, because umask is 002, the user and group attributes are not removed, but the others attributes are removed 2 (w ), therefore, when users:
 
When creating an archive: (-rw-)-(--- w-) ==>-rw-r-
When creating a directory: (drwxrwxrwx)-(--- w-) ==> drwxrwxr-x
 
Don't you believe it? You only need to use touch test and check the file properties of test! So how do you view your current umask? Just issue umask directly! Implementation:
 
[Root @ vbird test] # umask
0002
[Root @ vbird test] # touch test1
[Root @ vbird test] # mkdir test2
[Root @ vbird test] # ls-l
-Rw-r-1 root 0 Oct 22 00:00 test1
Drwxrwxr-x 2 root 4096 Oct 22 00:00 test2/
What have you found? Haha! The property of Test1 is 666-002 = 664! Correct? Yes! Correct! What about the directory test2? Is 777-002 = 775! Correct!
[Root @ vbird test] # umask 003
[Root @ vbird test] # touch test3
[Root @ vbird test] # mkdir test4
[Root @ vbird test] # ll
-Rw-r-1 root 0 Oct 22 00:03 test3
Drwxrwxr-2 root 4096 Oct 22 00:03 test4/
Hey! What is the difference between the attribute and the attribute ?? Why? Cutting Shenxi? Est3 666-003 = 663. What is this ?! 663 should be-rw-wx! How is the above attribute! Haha! He must be particularly stressed here! "Try not to add or subtract numbers !』 It is easy to cause problems similar to the above! You should think like this (-rw-)-(--- wx) =-rw-r-that's right! Do you understand? Do not use decimal numbers! If it is sufficient, it can be calculated in binary format. if you do not know it, you can use rwx to calculate it!
From the above example, you can easily find the usage of umask! This umask can be modified in/etc/bashrc! By default, the root umask is set to 022, while the average user is set to 002. because the write permission is very serious, the default permission will be removed! In addition, because root is important! Therefore, for the sake of security, the write attribute of the same group is removed! This also contributes to security!
For example, for the u m a s k value 0 0 2, what is the default creation permission for the corresponding files and directories?
Step 1: Write down the mode with all permissions, namely 7 7 7 (all users have read, write, and execute permissions ).
Step 2: write the corresponding bits in the following line according to the u m a s k value. In this example, it is 0 0 2.
Step 3: In the next row, remember that no matching bits exist in the above two rows. This is the default directory creation permission.
Remember this method with a little practice.
Step 4: for a file, you cannot have the file permission when creating the file. you only need to remove the corresponding execution permission bit, that is
Yes.
In this example, the u m a s k value is 0 0 2:
1) Maximum file permission: rwx (777)
2) umask value: 0 0 2--w-
3) directory permission: rwx r-x (775). This is the default permission for directory creation.
4) file permission rw-r-(664) this is the default permission for file creation.
The following is another example. assume that the u m a s k value is 0 2 2:
1) Maximum file permission: rwx (777)
2) u m a s k value is 0 2 2--w-
3) directory permission: rwx r-x (755). This is the default permission for directory creation.
4) file permission rw-r-(644) this is the default permission for file creation.

Author "☆cainiao Afan's path to growth"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.