How to Set umask

Source: Internet
Author: User
When you first log on to the system, the u m a s k Command determines the default mode of file creation. This command actually corresponds
The C h m o d command is the opposite. Your system administrator must set a reasonable u m a s k value for you to ensure that
Files have the desired default permissions to prevent other users from having the write permission on your files.
After logging on, you can use the u m a s k Command according to your preference to change the default permissions for file creation. Corresponding
Is valid until you exit the s h e l or use another u m a s k Command.
Generally, the u m a s k Command is set in the/e t C/p r o f I l e file. Every user will reference this document during login.
So if you want to change the u m a s k of all users, you can add corresponding entries to the file. If you want to be permanent
Set your u m a s k value, then put it in your $ h o m e directory. p r o f I l e or. B a s h _ p r o f I l e file.

How to calculate umask value
The u m a s k command allows you to set the default mode for file creation, corresponding to each type of users (file owner, users in the same group,
Other users) have a number in the corresponding u m a s k value. For files, the maximum value of this number is 6. System
You cannot grant the execution permission to a text file when creating it. You must use the C h m o d command to add this permission after the file is created.
Permission. You can set the execution permission for the directory. For the directory, the number in the u m a s k can be up to 7.
The command is generally in the following format:
Umask NNN
Where n is u m a s k 0 0 0-7 7 7.
Let's look at some examples.
Calculate your u m a s k value:
There are several ways to calculate the u m a s k value. By setting the u m a s k value, you can set the missing values for newly created files and directories.
Save permissions. Table 1-8 lists the u m a s k values corresponding to the permission phase.
When calculating the u m a s k value, you can create a default value for each type of user in this table according to the required file/directory
Permission to find the corresponding u m a s k value.
For example, the default permissions for creating files and directories corresponding to the u m a s k value 002 are 6 6 4 and 7 7 5, respectively.
There is another method for calculating the u m a s k value. We only need to remember that u m a s k is "Taking away" the corresponding bit from the permission, that is

Table 1-8 umask values and permissions
U m a s k file directory
0 6 7
1 6 6
2 4 5
3 4 4
4 2 3
5 2 2
6 0 1
7 0 0
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: The file cannot have the execution permission when it is created. 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.

Common umask values
U m a s k value directory file
022 755 644
027 750 640
002 775 664
006 771 660
007 770 660
If you want to know the current umask value, you can use the u m a s k command:

To change the u m a s k value, you only need to use the u m a s k Command to set a new value:
$ Umask 002
Check whether the system has accepted the new u m a s k value:
Before using the u m a s k Command, you must determine the file/Directory Creation default permissions you want. No
Some very strange results may be obtained. For example, if you set the u m a s k value to 6 0 0, then the created file/Object
The default permission is 0, 6, and 6.

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.