Linux user permission learning notes

Source: Internet
Author: User

Each Linux file has four types of access permissions: readable (r), writable (w), executable (x), and unauthenticated (-).
Use the ls-l command to view the permissions of a file or directory.
Accurate. The first field consists of 10 characters, as shown below:
-Rwxr-xr-x
The first parameter indicates the file type,-indicates the file, and d indicates the directory.
2-4 bits indicate the permissions of the file owner and u permissions.
5-7 digits indicate the permissions of the members of the file owner group, and g permission.
The 8-10 bits indicate the permissions of users outside the owner's group, and the o permission.
The sum of 2-10 bits is sometimes called a permission.

Chmod

This command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers. Chmod is a command used to change the file or directory permissions. However, only root, the owner of the file and the super-Permission user, has this permission.

 

As we have mentioned earlier, the file or directory permission bit has a total of 9 locations, the file owner, the file owner group occupies three locations, and other users each occupies three locations. Let's look at an example:

-rwxr-xr-x 1 root root 0 04-23 20:11 linuxsir007.txt

Note:

1. Number Description of the chmod octal syntax;

r     4w     2 x     1 -     0

The permissions of the owner are expressed in numbers: the sum of the three permissions of the owner. For example, in the above example, the owner's permission is rwx, that is, 4 + 2 + 1, which should be 7;

The permissions of a group are expressed in numbers: the sum of the number of the permissions of the group. For example, in the above example, r-x, that is, 4 + 0 + 1, should be 5;

The number of permissions of other users indicates the sum of the numbers of other user permission bits. For example, in the above example, It is r-x, that is, 4 + 0 + 1, which should be 5;

For example, changing the permissions of a file

But for a folder

1. If you want to change the permissions of the folder without changing the permissions of its sub-files, you do not need to add any parameters.

View folders and all subfolders

2. Change the permissions of itself and subfolders

3. Do not change the permissions of the sub-folder.

 

[root@localhost ~]# chmod -R 644 bin/.[a-z]*

In the above example, chmod will match all files starting with. a to. z.

-------------------------------------- Split line --------------------------------------

Common commands for Linux User Management

Common commands for Linux user and group management

Linux _ users, groups, and permissions

Linux users and group commands

Linux User and permission management

-------------------------------------- Split line --------------------------------------

2. Use the chmod mnemonic syntax to change the file or directory permissions.

The chmod mnemonic syntax is relatively simple. when changing the file or directory permissions, it is done in a more intuitive form of characters. In the mnemonic syntax, the relevant letters are defined;

User or user group definition:

U represents the owner

G stands for group

O stands for other users

A Represents the owner, group, and other users, that is, all of the above three users (or groups;

Permission definition letters: r indicates read permission; w indicates write permission; x indicates execution permission;

Add or remove characters to the permission;

-Remove related permissions. + adds related permissions;


[Root @ localhost ~] # Chmod ugo-x linuxsir007.txt note: the execution permissions of the owner, user group, and other users are revoked.

[Root @ localhost ~] # Chmod u + x linuxsir007.txt note: the execution permission is added to the file owner.

[Root @ localhost ~] # Chmod u-x, go + rw linuxsir007.txt Note: minus the execution right of the file owner to the file, adding the readable and writable permission of the Group and other users to the file

The mnable syntax is more flexible and convenient to combine; for example;

U = r + x adds read and write permissions to the file owner;

Ug = rwx, o = r Add read, write, and execute permissions for the owner and group, and set read permissions for other users.

A + x is the owner, group, and other users of the file;

G = u. The file owner and owner have the same permissions;

 

The-R parameter is required for directory permission settings;

Like the octal method, if we have the same attributes for a directory and Its subdirectories and files, we can use the-R parameter;

[root@localhost ~]# chmod -R a+rwx testdir/

 

This article permanently updates the link address:

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.