Linux articles (one)---umask and chmod

Source: Internet
Author: User
Tags access properties

first, the useThis article will introduce the commands related to the file access mode in the Linux environment.
Umask is used to set the default file access mode screen value, chmod used to change the file access mode.
This article will choose the ubuntu14.04 release as a descriptive narrative basis.

ii. mode of access to documentsLinux uses file access mode to ensure file security, and a 12bit data structure that represents 4 sets of properties for file access mode:
1, SUID, SGID, sticky attributes, also called special attributes.
2, the user's read, write, can run properties, also called user attributes.


3. Read, write, and run properties of the group to which the user belongs. Also called the user belongs to the group attribute.
4. Read, write, and run properties of other users in the group; also called other user attributes.
There are two ways to show these properties: One is the literal representation. R means readable. W indicates writable. X indicates that it is operational, and S indicates that the property is disabled by setting suid,-.

Use the Ls-al command to see the file access properties represented by the text mode. Another representation is octal, which divides the 12bit into 4 groups. Each group can be represented by octal, for example, the user octal value 7 (binary 111) is readable, writable, and can be run, and 5 (binary 101) is readable, non-writable, and can be run.


Both of these representations have advantages and disadvantages. Text representation is intuitive. Octal notation is concise.



third, suid and Sgid propertiesThe Suid property is only related to the executable file.

Under normal circumstances. When the user starts the executable file, the executable is started with the permissions of the current user. Assuming that the Suid property is set, the executable file is started with the permissions of all the files, regardless of who the current user is.
For example, the current user is Zsy, and the all that can run the file passwd is root, assuming the Suid property is not set, then when the Zsy user starts passwd can run the program. passwd permissions are just the permissions that Zsy has. The/etc/shadow file cannot be changed; The Suid property is set. Then when the Zsy user starts passwd to run the program. passwd permissions are root-owned and can change/etc/shadow.
The Sgid property acts similarly, assuming that the Sgid property is set. Then you have the permissions of the group to which the file belongs.

The stat command Stat command is able to view some of the basic properties of a file: File size, block size, file access mode, the full ID of the file, the ID of the group to which the file belongs, the file creation time, and so on.
Syntax: stat filename

Like what. Use the Stat command to view the properties of the passwd file.

Can see passwd's file access mode octal representation is 4755, 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, and then actively disables the blocked properties when you create a new file.
Syntax: Umask value
For example, setting the file access mode with the Umask 2 command has a shielded value of 2, or 0002.

Then when you create a new file, you are actively setting the Write permission for other properties to be disabled.

Six, chmod command chmod command to change the file access mode.
Syntax: chmod file access mode (text representation or octal notation) filename
Like what. Use the chmod command to add the executable permissions of the file as a literal representation, chmod u+x readme.md, or add the executable permission for the file in octal notation chmod 644 readme.md.
The implication of u+x is that u represents a user attribute in file access mode. + means add, and X indicates operational permissions.


Octal notation is more concise. It is recommended that you use octal notation to change the file's access mode.



Vii. Summary of the Linux system files have a very wide range of properties, such as: File size, file owners, files belong to the group, file access mode, etc., the status of the file access mode attribute is more important. Therefore, the concept of file access mode and related commands Umask and chmod are highlighted.

File access patterns are expressed in the form of text representations and octal representations. Should be proficient in mastering.

The SUID bit of the special attribute affects the running permissions of the executable file, and the reader should understand the meaning and usage of suid correctly.


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


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Linux articles (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.