In-depth understanding of umask in new linux file permission settings

In-depth understanding of umask in new linux file permission settings

Preface

The origin is a question 1: If your umask is set to 022, what are the default permissions for the files you create?

This reminds me of another question I was asked 2: What permissions does 777 represent?

User Group Description

-rwxrw-r--1 root root 1213 Feb 2 09:39 abc
  • The first character represents a file (-), a directory (d), or a link (l).
  • The remaining characters are grouped in groups of 3 (rwx), read (r), write (w), execute (x)
  • The first group rwx: The file owner's permissions are read, write, and execute
  • The second group rw-: users in the same group as the file owner have read and write permissions but cannot execute
  • The third group r--: The permissions for other users who are not in the same group as the file owner are read but not write and execute
  • It can also be expressed digitally as: r=4, w=2, x=1, because rwx represents three binary numbers, these numbers can be calculated exactly.

Digital Rights Description

So back to question 2, 777 is a three-digit octal number, corresponding to 111111111, which means that all three groups are readable, writable, and executable. We can use it like this:

chmod 755 abc //chmod changes the permissions of file abc to be readable, writable and executable by the file owner, and readable and executable by users in the same group and other groups

umask Description

umask is a permission mask, which represents the default permissions. It is used to calculate the default permissions for new objects created by the user based on the maximum default values ​​of 666 for files and 777 for folders.

For example, in question 1, the default permissions for creating a file are 666-022=644, which is -rw-r--r--

What is umask used for?

The default umask value is 022 (you can use the umask command to view it). At this time, the default permissions of the files you create are 644 (6-0, 6-2, 6-2), and the default permissions of the directories you create are 755 (7-0, 7-2, 7-2). You can verify it with ls -l. Now you should know the purpose of umask, which is to control the default permissions.

[root@bogon test]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@bogon test]# umask
[root@bogon test]# touch a.txt
[root@bogon test]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jul 3 00:40 a.txt
[root@bogon test]# mkdir b
[root@bogon test]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jul 3 00:40 a.txt
drwxr-xr-x. 2 root root 6 Jul 3 00:41 b

As can be seen above, the umask of root is 022 (the first 0 represents the special permission bit, which is not considered here), the default permissions of created files are 644, and the default permissions of created directories are 755.

Before understanding the use of umask, you need to explain the basic permissions of the file.

Linux file permissions
r w x
document You can view the file contents Can modify files You can start the file as a running program
Table of contents You can use ls to view the file names in the directory. You can create or delete files in the directory (you can't create with just w permission, you need x to cooperate) You can use cd to enter this directory ls -l to display the metadata information of the files in the directory

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the use of umask under Linux
  • Detailed explanation of the use principle and calculation method of the umask command under Linux

<<:  Detailed explanation of the implementation process of dual-master synchronization of partial tables in MySQL 5.7

>>:  How to use resident nodes for layer management in CocosCreator

Recommend

MySQL knowledge points for the second-level computer exam mysql alter command

Usage of alter command in mysql to edit table str...

How to upgrade https under Nginx

Purchase Certificate You can purchase it from Ali...

Introduction to JavaScript Number and Math Objects

Table of contents 1. Number in JavaScript 2. Math...

25 CSS frameworks, tools, software and templates shared

Sprite Cow download CSS Lint download Prefixr dow...

An article to understand the use of proxies in JavaScript

Table of contents What is an agent Basic knowledg...

MySQL Optimization Solution Reference

Problems that may arise from optimization Optimiz...

The most convenient way to build a Zookeeper server in history (recommended)

What is ZooKeeper ZooKeeper is a top-level projec...

How to add java startup command to tomcat service

My first server program I'm currently learnin...

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

How to use Antd's Form component in React to implement form functions

1. Construction components 1. A form must contain...

Vue implements multi-tab component

To see the effect directly, a right-click menu ha...