Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of umask usage

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is umask? When we log in to the system and create a file, there is always a default permission, so how does this permission come from? That's what umask does. umask sets the default permissions for the user to create files, which has the opposite effect of chmod, umask sets the permissions "complement," and chmod sets the file permissions code. The umask value is typically set in/etc/profile,$ [HOME]/.bash_profile, or $[HOME]/.profile. Your system administrator must set a reasonable umask value for you to ensure that the files you create have the desired default permissions and prevent other users from having write permissions on your files. After you've logged in, you can change the default permissions for file creation to suit your preferences using the umask command. The corresponding changes remain in effect until you exit the shell or use another umask command. In general, the umask command is set in the/etc /profile file, which is referenced by every user when logging in, so if you want to change the umask of all users, you can add the corresponding entry to the file. If you want to set your umask value permanently, put it in your.profile or.bash_profile file in your $HOME directory. B How to calculate umask value The umask command allows you to set the default mode for file creation. There is a number in the umask value for each type of user (file owner, group user, other user). For files, the maximum value of this number is 6. The system does not allow you to grant execution permission to a text file when it is created. You must add this permission with chmod after it is created. Directories allow execution permissions to be set, so that for directories, the number in the umask can be up to 7. The general form of the order is: umask nnn Where nnn is umask set 000-777. Let's look at some examples. Calculate your umask value: There are several ways to calculate umask values, and by setting umask values, you can set default permissions for newly created files and directories. The following table lists umask values corresponding to permission bits. When calculating the umask value, you can create default permissions in this table for each type of user according to the required file/directory to find the corresponding umask value. For example, umask value 002 corresponds to file and directory creation defaults of 6 6 4 and 7 7 5, respectively. There is another way to calculate umask values. We just need to remember that umask "takes" bits from permissions. umask values and permissions umask 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 umask value 0 0 2, what are the default create permissions for files and directories? As a first step, we write down the pattern with full permissions, i.e. 777 (all users have read, write, and execute permissions). Second, write down the corresponding bit in the lower line according to the umask value, in this case 0 0 2. Third, write down in the next line the bits that did not match in the first two lines. This is the default create permission for directories. With a little practice you can remember this method. Step 4: For files, you cannot have execution permission when creating them, as long as you remove the corresponding execution permission bit. This is the example above, where u m a s k has a value of 0 0 2: 1)Maximum permissions for files rwx (777) 2)umask value is 0 0 2 ----- -w- 3)directory permissions rwx rwx r-x (775) This is the default directory creation permission 4)File permissions rw- rw- r-- (664) This is the default permission for file creation Here is another example, assuming u m a s k is 0 2 2: 1)Maximum permissions for files rwx (777) 2 ) u m a s k value is 0 2-- -w- -w- 3)directory permissions rwx r-x r-x (755) This is the default directory creation permission 4)File permissions rw- r-- r-- (644) This is the default permission for file creation C Common umask values The following table lists some umask values and their corresponding directory and file permissions. Common umask values and corresponding file and directory permissions umask value directory file 0 22 7 5 5 6 4 4 0 27 7 5 0 6 4 0 0 02 7 7 5 6 6 4 0 06 7 7 1 6 6 0 0 07 7 7 0 6 6 0 D umask command If you want to know the current umask value, you can use the umask command: $umask If you want to change the umask value, simply use the umask command to set a new value: $ umask 002 Check if the system has accepted the new u m a s k value: $umask 002 $touch testfile $ls -l testfile rw- rw- r-- Be sure to figure out exactly what file/directory creation default permissions you want before using umask. Otherwise, you might get some very strange results; for example, if you set umask to 6 0 0, the file/item you create The default permissions are 0 6 6!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report