Home>Article>Operation and Maintenance> what is linux umask

what is linux umask

青灯夜游
青灯夜游 Original
2022-02-24 12:01:11 6522browse

umask is a command in Linux, used to create permission masks for user files, the syntax is "umask [-S][permission mask]"; among them, "permission mask" is composed of 3 octal consists of numbers. After subtracting the permission mask from the existing access permissions, the default permissions when creating the file can be generated.

what is linux umask

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

umask(user file-creatiopn mode mask) is a command in Linux that is used to specify the default permission mask when creating a file.

The umask command determines the default permissions to be set on any file or directory created

The umask command creates a mask for user files, which is the basis for the default permissions when creating a file or folder. . Usually we can use chmod to modify the permissions of files in Linux. The effect of umask is opposite to that of chmod. See below for details.

If there is no file mask, the default permissions of the file are 0666 and the default permissions of the folder are 0777.

Reason:

  • Creating files is generally used for reading and writing, so by default all users have read and write permissions, but no executable permissions, so the file creation The default permission is 0666

  • and the x permission of the folder represents the open permission, so this permission is required, so the default permission of the folder is 0777.

User mask function

The above permissions are the default permissions without umask. However, in order to protect the user's permission to create files and folders, the system will have a default user mask (umask) at this time. The default mask of most Linux systems is 022. The purpose of the user mask is to remove the permissions in the mask from the default permissions of the file when the user creates the file. So the permissions after the file is created are actually:

#文件创建权限 默认权限(文件0666,文件夹0777)-umask

So if the user does not modify the umask, the permissions to create the file are: 0666-0022=0644. The permissions to create a folder are: 0777-0022=0755

View and modify the default mask

View user mask:

#以数字方式查看掩码 umask # 以符号形式查看掩码 umask -S

can be used The umask command directly modifies the mask.

umask 0000

The mask modified by the above method only takes effect in the current tty. To take effect globally, you can write the umask value in /etc/profile or .bashrc

Related recommendations:《Linux video tutorial

The above is the detailed content of what is linux umask. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn