Linux essay (one)---umask and chmod

Source: Internet
Author: User
Tags access properties

first, the purposeThis article describes the commands related to file access patterns in the Linux environment.
The umask is used to set the default file access mode screen value; chmod is used to modify the access mode of the file.
This article will select the ubuntu14.04 release as the basis for the description.

Second, the file access modeLinux uses the file access mode to ensure file security, with a 12BIT data structure representing 4 sets of properties for the file access pattern:
1, SUID, SGID, sticky attributes, also called special attributes.
2, the user's reading, writing, executable properties, also known as user attributes.
3, the user belongs to the group's read, write, executable properties, also called the user belongs to the group properties.
4. Read, write, and execute properties of other users in the group, also called other user attributes.
These properties are presented in two ways: one is a literal representation, R is readable, W is writable, X is executable, and S indicates that the property is disabled by setting suid,-. Use the Ls-al command to view the file access properties represented by text. Another representation is octal, which divides the 12bit into 4 groups, each of which can be represented by octal, for example, the user octal value 7 (binary 111) is readable, writable, executable, 5 (binary 101) is readable, non-writable, and executable.

These two representations each have advantages and disadvantages, the text representation is intuitive, the octal representation is concise.



third, suid and Sgid propertiesthe Suid property is only relevant to the executable file. Normally, when a user launches the executable, the executable is started with the permissions of the current user, and if the Suid property is set, the executable is started with the permissions of the owner of the file, regardless of who the current user is.
For example, the current user is Zsy, and the owner of the executable file passwd is root, and if the Suid property is not set, passwd permissions are only passwd permissions when Zsy user launches Zsy executable and cannot modify/etc/shadow file If the Suid property is set, the passwd permission is the root-owned permission when the Zsy user launches the passwd executable, and the/etc/shadow can be modified.
The Sgid property acts similarly, and if you set the Sgid property, you have the permissions of the group to which the file belongs.

iv. Stat CommandThe stat command can view some of the basic properties of a file: File size, block size, file access mode, owner ID of the file, ID of the group to which the file belongs, file creation time, and so on.
Syntax: stat filename

For example, use the Stat command to view the properties of the passwd file. As you can see, the octal representation of passwd's file access mode is 4755, and the corresponding text representation is-rwsr-xr-x. This file sets the Suid and Sgid.



v. umask commandthe umask command sets the default file access mode masking value, which automatically disables blocked properties when new files are created.
Syntax: Umask value
For example, using the Umask 2 command to set the file access mode with a masked value of 2, or 0002. When you create a new file, the Write permission for the other properties is automatically set to disabled.

vi. chmod Commandthe chmod command can change the file's access mode.
Syntax: chmod file access mode (text representation or octal notation) filename
For example, use the chmod command to increase the executable permissions of a file in text notation, chmod u+x readme.md, or add executable permissions for a file in octal notation chmod 644 readme.md.
The meaning of the u+x is that u represents the user attribute in the file access mode, + represents an increase, and x represents the executable permission.
octal notation is relatively concise, so it is recommended to use octal notation to modify the file's access mode.

Vii. SummaryLinux system files have many kinds of properties, such as: File size, file owner, file belongs to the group, file access mode, etc., where the status of the file access mode is more important, so focus on the concept of file access mode and related commands Umask and chmod.

File access patterns are expressed in the form of text representations and octal representations, which should be mastered. The SUID bit of the special attribute affects the execution permission of the executable file, and the reader should correctly understand the meaning of the suid and how to use it.


Copyright Notice:original works, such as non-commercial reprint, please specify the source, such as commercial reprint publication, please contact the author.

Linux essay (one)---umask and chmod

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.