Common knowledge about chmod

Source: Internet
Author: User
Some common knowledge about chmod-general Linux technology-Linux technology and application information. For details, refer to the following section. 1. Basic usage

Permission: All Users

Usage: chmod [-cfvR] [-- help] [-- version] mode file...

Note: file access permissions for Linux/Unix are classified into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxX]...] [,...], u indicates the owner of the file, g indicates that the owner of the file belongs to the same group, o indicates that the owner of the file belongs to other people, and a indicates that all three are.

+ Adds a permission,-Indicates canceling the permission, and = indicates a unique permission.

R indicates that the file can be read, w indicates that the file can be written, and x indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable.

-C: if the permission of the file has been changed, the change action is displayed.

-F: Do not display an error message if the file permission cannot be changed.

-V: displays details of permission changes.

-R: Change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)

-- Help: displays auxiliary instructions

-- Version: displays the version.

Example: Set the file file1.txt to readable by all users:

Chmod ugo + r file1.txt

Set file1.txt to readable:

Chmod a + r file1.txt

Set file1.txt and file2.txt as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:

Chmod ug + w, o-w file1.txt file2.txt

Set ex1.py to only the owner of the file to execute:

Chmod u + x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:

Chmod-R a + r *

In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.

Syntax: chmod abc file

Each a, B, and c is a number, indicating the permissions of the User, Group, and Other respectively.

R = 4, w = 2, x = 1

If you want the rwx attribute, 4 + 2 + 1 = 7;

If the rw-attribute is required, 4 + 2 = 6;

If you want the r-x attribute, 4 + 1 = 7.

Example:

Chmod a = rwx file and chmod 777 file have the same effect

Chmod ug = rwx, o = x file, and chmod 771 file have the same effect.

If you use chmod 4755 filename, you can grant root permissions to this program.

2. special permissions for the file: SUID/SGID/Sticky Bit

1. set UID: When the executable bit (x) of the "owner permission combination" in the file system is replaced by s (rws ------), it constitutes a special permission rule Set UID (SUID. The setting is only valid for binary executable files in the system and cannot be applied to Shell scripts.

2. set GID: When the executable bit (x) In the permission combination of the user group (group) where the owner is located is replaced by s (for example, --- rws ---), it constitutes the permission setting of Set GID. SGID can be set for binary files or directories.

3. sticky Bit: When the executable Bit (x) in the file system "others" permission combination is replaced by t (for example, ------ rwt), it constitutes the Sticky Bit permission settings. It is only valid for directories.

SUID and SGID are used to temporarily obtain the permissions of a non-file owner (or group) for executing (or operating directory) files.

SBIT is used for access control. When it sets this attribute for a directory, all files in the directory, even if others have w attributes, you cannot rename, move, or delete it.

Setting method:

If you have mastered the rules for expressing permissions with (octal) numbers, it is easy to configure them with the chmod command. The following are the octal values corresponding to the SUID/SGID/Sticky Bit conventions:

SUID = 4
SGID = 2
SBIT = 1

When setting, we place the number indicating the special permission before the other three-digit permission.

For example:

SUID indicates that the number is 4. For example, the result of 4755 is-rwsr-xr-x.

SGID represents 2. For example, the result of 6755 is-rwsr-sr-x.

SBIT indicates that the number is 1. For example, the result of 7755 is-rwsr-sr-t.

(Of course, the chmod setting of 7755 does not make much sense. Here is just a demonstration)

It should be noted that the four-digit format is the standard writing. We usually write the last three digits, for example, 755. The system will process your 755 as 0755.

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.