Linux file default permissions: Umask__linux

Source: Internet
Author: User
Tags mkdir

Now, we know how to create or change the attributes of a directory or file, but you know what the default property is when you create a new file or directory. Then it has to do with umask. So, what is Umask? Basically, umask is specifying "the default value of the property at the time the current user establishes the file or directory." So, how to know or set umask it. It specifies the condition in the following way: [Root@linux ~]# Umask
0022
[Root@linux ~]# Umask-s
There are two ways to view the U=rwx,g=rx,o=rx, one is to enter the umask directly, you can see the number type of permission to set the score, one is to add the-s (symbolic) parameter, will display the permissions in the form of symbolic type. Strangely, there are 4 sets of numbers umask. Isn't there only 3 groups? That's right. The first group is special permissions, let's ignore it first, so look at the back 3 groups.
The directory is not the same as the file on the properties of the default permissions. Because we do not want the file to have executable power, by default, the file does not have execute (x) permissions. So:
• If the user is established as "file" then the default "no executable (x) project", that is, only RW two items, that is, the maximum is 666 points, the default properties are as follows:
-rw-rw-rw-
• If the user is established as "directory", because X is related to whether or not this directory is accessible, the default is all permissions are open, that is 777 points, the default properties are as follows:
Drwxrwxrwx
UMASK Specifies the permission to be lost for this default value. Because R, W, X is 4, 2, 1, so. In other words, when you want to remove the right to write, is to enter 2, and if you want to remove the right to read, that is 4, then to remove the read and write permission, that is, 6, and to remove the execution and write permission, that is, 3. Excuse me, what is 5. is the right to read and execute. If the above example illustrates, because the umask is 022, so the user is not stripped of attributes, but the group and others properties are removed 2 (that is, w this attribute), then when users:
• When creating documents: (-rw-rw-rw-) – (-----w--w-) ==>-rw-r--r--
• When creating a directory: (DRWXRWXRWX) – (d----w--w-) ==> drwxr-xr-x
Let's test and see. [Root@linux ~]# Umask
0022
[Root@linux ~]# Touch Test1
[Root@linux ~]# mkdir test2
[Root@linux ~]# LL
-rw-r--r--1 root 0 00:36 test1
Drwxr-xr-x 2 root root 4096 June 00:36 test2 see it. There is nothing wrong with determining attributes. If you want to make users with the user group can also access the file. That is, if Dmtsai is a person in the Users group, and the files that Dmtsai does want to be accessible to people in the Users group, this is also a privilege issue that is often taken into account in a team development plan. In such cases, umask naturally cannot cancel the group's W permission, that is to say, we want to make the file should be-rw-rw-r--, so, umask should be 002 is good (only remove the others W permissions). How to set up Umask. Simple enough, enter 002 directly after the umask. [Root@linux ~]# umask 002
[Root@linux ~]# Touch Test3
[Root@linux ~]# mkdir test4
[Root@linux ~]# LL
-rw-rw-r--1 root 0 00:41 test3
Drwxrwxr-x 2 root root 4096 00:41 test4 So, this umask is very related to the default permissions for files and directories. This concept can be used on any server, especially in the future when setting up a file server, such as a Samba server or an FTP server. This involves the question of whether the user will be able to use the file further. Don't take it lightly.
Example four:Assuming Umask is 003, please use the umask to establish the file and directory right
What the limit is.
For:
Umask is 003, so the property that is removed is--------wx, so:
File: (-rw-rw-rw-)-(--------wx) =-rw-rw-r--
Table of Contents: (DRWXRWXRWX)-(--------wx) = drwxrwxr--

hint: in the calculation of Umask and permissions, the textbook prefers to use binary method to do and and not, but I prefer to use the symbolic method of calculation, Lenovo is relatively easy. However, some books or BBS, some people like to use the file default property 666 is subtracted from the directory default property 777来 and Umask. This is not good. In Example 4, if you use the default property to add and subtract, the file becomes: 666-003=663, or-RW-RW--WX, is completely wrong. Think about it, the original file has been removed from the default properties of x, how can suddenly come out. So, this place needs special care.

In the default case, the umask of root will remove the more properties, the root umask default is 022, which is based on security considerations. General identity users typically have a umask of 002, which preserves the write power to the same user group. In fact, the default Umask settings can refer to the contents of the/ETC/BASHRC file, however, it is not recommended to modify the file, you can refer to the Environment parameter settings file (~/.BASHRC) described in chapter 11th.




From:http://hi.baidu.com/fengyun409/item/82cd158ffe7f67c8b17154e7

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.