Umask permission mask in Linux

Permission mask

umask creates a mask for user files and is the basis for the default permissions when creating files or folders. Usually we can use chmod to modify the permissions of files in Linux. The role of umask is opposite to the effect of chmod, see below for details.

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

the reason:

  • File creation is generally used for reading and writing, so by default all users have read and write permissions, but no executable permissions, so the default permission for file creation is 0666
  • The x permission of the folder indicates the opening permission, so this permission must have, so the default permission of the folder is 0777.
  • The first bit represents special authority (suid: 4, sgid: 2, sbit: 1), not octal. Generally set it to 0, which is the system default.

Role of permission mask

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). Most Linux systems have a default mask of 022. The role of the user mask is to remove the permissions from the mask from the default permissions of the file when the user creates the file. So the permissions after the file is actually created are:

#File creation permission
Default permissions (file 0666, folder 0777)-umask

 

Therefore, without modifying the umask, the permission to create files is: 0666-0022 = 0644. The permission to create a folder is: 0777-0022 = 0755

View and modify the default mask

View user mask:

#View the mask digitally
umask
# View the mask in symbolic form
umask -S

 

You can use the umask command to modify the mask directly.

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

Guess you like

Origin www.cnblogs.com/FengZeng666/p/12717441.html