Linux File and directory permissions

Source: Internet
Author: User

Linux File and directory permissions

View permissions for a file

The permissions for a file and directory, as shown below,

Localhost:workspace-github xinxingegeya$ ls-ltotal 8-rw-r--r--1 Xinxingegeya staff 8 19:10 a.htmldrwxr-xr-x 2 Xinxingegeya Staff 8 18:17 sample

A total of 10 digits, of which: the first one-represents the type

The three rw-in the middle represent the permissions owned by the owner (user)

Then the three r--represent the permissions that the group has.

The last three r--represent the rights that other people (other) have

which

R indicates that a file can be read (read)

W indicates that the file can be written (write)

x indicates that the file can be executed (if it is a program)

-Indicates that the appropriate permission has not been granted

Note: The directory problem to view file permissions: If you have a folder/a/b/c

The file that executes Ls-l/a/b view permission is not B, but the permission to view C.

Ls-l/A view of permissions for file B

Ls-l/a/b viewing permissions for C files

Ls-l/a/b/c viewing permissions for C files


Modify Permissions chmod command

The following actions,

Localhost:workspace-github xinxingegeya$ chmod o+w a.htmllocalhost:workspace-github xinxingegeya$ ls-ltotal 8- Rw-r--rw-1 Xinxingegeya Staff 8 19:10 a.htmldrwxr-xr-x 2 Xinxingegeya staff 8 18:17 sample

chmod o+w a.html means to increase the W permission for others, you can see that there is a W in the last three characters, which means that the permission of the other user is RW.

? ? chmod u+x filename here, u means user refers to users themselves; + means add permission; x refers to an executable file

Symbol mode

You can set multiple items using the symbol mode: Who (user type), operator (operator), and permission (permissions), and each item's settings can be separated by commas. The command chmod will modify the WHO-specified user type to access the file, and the user type is described by one or more letters in the WHO location, as shown in the WHO notation schema table:

W.H.O. User Type Description
U User File owner
G Group The group where the file owner resides
O Others All other users
A All Used by the user, equivalent to Ugo


Operator symbol Mode table:

Operator Description
+ Add permissions for the specified user type
- Remove permissions for a specified user type
= Set the settings for the specified user right to reset all permissions for the user type


Permission symbol Mode table:

Mode name Description
R Read Set as readable permission
W Write Set to writable permission
X Execute permissions Set to executable permission
X Special Execution permissions File permission settings can only be performed if the file is a directory file, or if other types of users have executable permissions
S Setuid/gid When the file is executed, set the file's setuid or setgid permissions according to the user type specified by the WHO parameter
T Paste bit Set the paste bit, only the superuser can set the bit, only the file owner u can use that bit


Eight-binary syntax

The chmod command can use octal numbers to specify permissions. The permission bit of a file or directory is controlled by 9 permission bits, each of which is a set of three bits, which are read, write, execute, read, write, execute, and other users (other) of the file owner (user). Historically, file permissions were placed in a bitmask, with the bits specified in the mask set to 1, to indicate that a class had a corresponding priority.

chmod the octal syntax for the number description:

R 4

W 2

X 1

-0

The owner's authority is expressed in numbers: the sum of the numbers of the three permission bits of the master. such as rwx, that is, 4+2+1, should be 7.

The permissions of the user group are expressed in numbers: the sum of the number of permission bits that belong to the group. such as rw-, that is, 4+2+0, should be 6.

Other user's permission number expression: The sum of the numbers added to the other user's permission bits. such as R-x, that is, 4+0+1, should be 5.


Use this method to modify the permissions of the file,

Localhost:workspace-github xinxingegeya$ chmod 444 a.htmllocalhost:workspace-github xinxingegeya$ ls-ltotal 8- r--r--r--1 Xinxingegeya Staff 8 19:10 a.htmldrwxr-xr-x 2 Xinxingegeya staff 8 18:17 sample

chmod 444 a.html means that you only have read permissions and no other permissions.


Recursively modifying file permissions

The sample directory has a file b.html, recursively modifying the sample and b.html for the same permissions.

Localhost:workspace-github xinxingegeya$ chmod-r ug+rwx sample Localhost:workspace-github xinxingegeya$ ls-ltotal 8- r--r--r--1 Xinxingegeya Staff 8 19:10 a.htmldrwxrwxr--3 Xinxingegeya Staff 102 8 20:11 Samplelocalhost  : Workspace-github xinxingegeya$ cd samplelocalhost:sample xinxingegeya$ ls-ltotal 8-rwxrwxr--1 Xinxingegeya Staff 17 8 20:11 b.html

Chmod-r ug+rwx Sample

Recursively modifies the permissions of the sample directory and its files.

Reference: http://zhaoyuqiang.blog.51cto.com/6328846/1214718

Https://zh.wikipedia.org/wiki/Chmod

http://sweetpotato.blog.51cto.com/533893/1355372

===========end===========

Linux File and directory permissions

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.