Linux Learning-umask Detailed

Source: Internet
Author: User

umask --Indicates the default permissions when creating a file (that is, it does not need to be set when creating a file)


For example, we found

under root user , touch A, the default permission for file A is 644

under Normal user , touch B, the default permission for file B is 664

644 and 664 We are not set, and the key factor is umask

Analysis:


            directory               file
  highest privilege         777   RWXRWXRWX
          666   rw-rw-rw-

      command umask can view the current user's umask value    


Root Normal User
Umask 022 002


in combination with the above examples, we know:

Default permissions = Maximum permissions-umask(644=666-022//664=666-002)

but:

when Umask is 011, the default permission to create a file should be 6 55, but the default permissions are 666 when actually running

666-rw-rw-rw-

011,-----x--x

to subtract:

666 <-rw-rw-rw-

(This special case only appears in the file because the file [except the binary file] does not have x Execute permission)

So, when viewing the umask of a file, we pay special attention to whether there is an odd digit (x = 1)


umask + value Modify the current user's umask such as: Umask 044

However, this set of umask will restore the original value when the user logs back in, we can save the modified umask in ~/.BASHRC

***************************

Vim ~/.BASHRC

Add umask at the end of the file 044

Save exit

Re-login user is saved successfully

***************************


Case:

Liu closed three brothers belong to Shu this additional user group, has a shared directory, called Shuguo, three brothers in Shuguo under the creation of files, can be modified between each other. Other people without any permission, the three brothers created files can only be deleted by themselves. (default setting by Umask value)

Groupadd Shu

useradd-g shu Liubei

useradd-g shu Guanyu

useradd-g shu Zhangfei

mkdir Shuguo

chgrp shu shuguo/ /*shuguo directory belongs to the group changed to shu*/

chmod g+s shuguo/ / * Make Liu closing files created by shu*/

chmod o+t shuguo/ / * Make Liu closed the files created can only be deleted by themselves * /

chmod g+w shuguo/ /* Make Liu Closure can modify and execute files under Shuguo */

umask 006


Linux Learning-umask Detailed

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.