Linux Basic Permissions Learning

Source: Internet
Author: User

Concept

Permissions are what users can do with resources--there are three important concepts involved: users, resources, operations.

First of all, Linux users are divided into: u, G, O, is the user, user group, other users. -the user here refers to the owner !!! Be sure to remember!

Second, everything in Linux is files, so the resources in Linux are files. (Let's say so)

Finally, the permissions of the files in Linux are divided into three types: R, W, X, which is read, write, and execute.

In addition, the binary permission, R, W, x corresponds to 4, 2, 1, so the permission can be expressed or given by a number. For example, the Read permission corresponds to 4, read and Write permission corresponds to 6, read Execute permission corresponds to 5, and read and write Execute permission corresponds to 7.

the default permissions for files in Linux are 666, can be read and written, but not executed, but there is also a umask value, so the actual default permissions are combined.

Some of the data are considered 666-umask, which is not correct, because umask may contain 666 values that are not contained. For example, 666-0033=633, this is not true because the default cannot contain X permissions! If you do not want to subtract, you need to umask-0011, that is, to remove the executable permissions.

The most straightforward method is to convert 666 and umask into rwx form, then subtract.

the default permissions for the directory in Linux are 777, can read and write executable, also need to combine umask to get the actual default permissions !!!

Umask can temporarily modify values, and permanent changes need to be set in environment variables:/etc/profile

View

You can view the permissions information for a file by using the Ls-l command:

[Email protected] ~]#ls-L Total Dosage --RW-------.1Root root1289December7  +: theanaconda-ks.cfg-rw-r--r--.1Root root28250December7  +: the Install. Log-rw-r--r--.1Root root7572December7  +: - Install. log.syslog

Analytical

Take the information for the Install.log file above as an example, and its Permissions section -rw-r--r--. . Length 12, this can be divided into 1 + 3 + 3 + 3 + 1.

The first digit represents the file type:-Represents the file, D represents the directory, L represents the connection, and so on.

The following three groups of three bits correspond to user, user group, other user's read and write execute permission respectively;

The last one is related to the ACL, tentatively.

Change permissions

chmod command

There are several forms:

chmod u+rwx,g+r,o+r  filechmod u=rwx,g=r,o=r  filechmod  Filechmod755  file

Skilled after the recommended use of digital form!

In addition, the-r option indicates recursion, which sets permissions for all files under the directory.

Special

Read and write execution permissions are well understood for files (as opposed to directories), but not easy to understand for catalogs.

For example, suppose you have a directory ~/dir/that gives you permission to write W, then you can't delete the directory, and the files in the directory!

The reason relates to the underlying knowledge, tentatively.

In short, Linux, the most important thing for a file is X permissions, but for the directory, the most important is the W permissions.

That is, only 0, 5 (RX), and 7 (RWX) are valid for the directory.

Linux Basic Permissions Learning

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.