Linux directory and File permissions analysis

Source: Internet
Author: User

If all things are objects in the Java world, then in the Linux world, everything can be said to be files. Linux files are generally divided into two types, general files and directory files. File permissions are critical to data security, and it is necessary to be aware of the general file permissions and the meaning of directory file permissions.

    • The importance of permissions to files

Files are places where data is actually contained, including generic text files, database content documents, binary executable files (binary program), and so on. Therefore, the permissions for the file, its meaning is this:

R (read): Can read the actual contents of this file, such as reading the text file content, etc.;

W (write): You can edit, add, or modify the contents of the file (without deleting the file);

x (eXecute): The file has permissions that can be executed by the system.

Readable (r) represents a good understanding of reading the contents of a file, then executable (x)? Because the ability to execute a file under Windows is determined by the "extension", for example:. exe,. bat,. com, and so on, whether or not our files can be executed under Linux, is determined by having the "X" Permission! There is no absolute relationship with the file name ! As for the last W this permission? When you have W permission on a file, you can have permission to write/edit/Add/Modify the contents of the file, but you do not have permission to delete the file itself ! for the rwx of the file, it is mainly for "content of the file", and the existence of file name is not related! Because the file is recording the actual data!

    • The importance of permissions to the directory

The file is where the actual data is stored, so what is the main store for the catalog? The main contents of the directory in the record file name list, the file name and the directory is strongly connected! So what is the meaning of the R, W, and X to the directory if it is for the directory?

   R (read contents in directory):

Indicates that you have permission to read the directory structure manifest, so when you have permission to read (r) a directory, you can query the file name data under that directory. So you can use the LS command to display the table of contents of this directory!

w (Modify contents of directory):

This writable permission is great for the directory! Because it indicates that you have permissions to move the directory structure manifest, that is, the following permissions:

      • Create a new file and directory;
      • Delete files and directories that already exist, regardless of the permissions of the file! )
      • Renaming a file or directory that already exists;
      • Move the files and directory locations within the directory. In summary, the directory's W permission is related to the file name of the directory under the different action!

x (Access directory):

So, what is the use of directory execution permissions? The directory is just a record file name, you can not carry it? That's right! The directory cannot be executed, and the X of the directory represents the user's ability to enter the directory as a working directory! the so-called working directory is the directory where you are now! For example, when you log in to Linux, your home folder is your current working directory. The command to change the directory is "CD" (Changedirectory)!

Now suppose the file is a bunch of file folders, so you might be able to write/change some data on it. And "Catalogs are a bunch of drawers," so you can sort the folders into different drawers. So the main purpose of the drawer is to take out/put the Data folder Oh! Now let's take a look at the data:

Components Content Overlapping objects R W X
File Details data File Data folder Read File contents Modify File Contents Execute File Contents
Directory Filename Category Drawer Read the file name Modify file name Permission to enter the directory (key)

  

According to the above analysis, you can see, for the general file, rwx is mainly for the "content of the file" to design permissions, for the directory, RWX is "directory of File Name list" to design permissions. The most interesting is probably the directory of the X permission! "How does the file name execute?" It makes no sense! In fact, this X-permission design, is equivalent to "the directory, that is, the drawer" key "! How can you open a drawer without a key? Right!

    • Specific examples

Example 1: The permissions for a directory are as follows:

  drwxr--r--3 root root 4096 June 08:35 test

The system has an account name called Hah, this account does not support the root group, what is hah to this directory have permissions? Can I switch to this directory? A: Hah has only R permissions on this directory, so hah can query the list of file names under this directory. Because HAH does not have X's permission, that is, HAH does not have the key to this drawer! so hah can't switch to this directory !

In this example above, because HAH has the permission of R, because it is at first glance, it seems to have access to this directory, in fact, it is wrong. Can not enter a directory, only with the directory of the X permission related! In addition, working directory is very important for the execution of instructions, if you do not have X permission in a directory, then you can not switch to the directory, you can not execute any instructions under that directory, even if you have the directory's R or W permissions.

Example 2: If an account name is called Xixi, his home folder has [rwx] permissions to the directory in/home/xixi/,xixi. If there is a file named The_root.data in this directory, the file has the following permissions:

  -rwx------1 root root 4365 Sep 23:20 the_root.data

What is the Xixi permissions on this file? Can I delete this file? A: As shown above, because Xixi is "others" to this file, the file is unreadable, cannot be edited, and cannot be executed, meaning that he cannot change the contents of the file. But since this file is in his home folder, he has the full permissions of rwx in this directory, so for the_root.data this "file name", he is able to "delete"! The conclusion is thatXixi This user can delete the_root.data this file !

The above example explains this, assuming that there is a baffling person, with a completely sealed data clip in your office drawer, because completely sealed you can not open, see the Data folder internal data (for the file, you do not have permission). But since this data clip is placed in your drawer, you can of course take out/put any data in this drawer (for the directory you have all the permissions). So, the situation is: you open the drawer, take out this can't see the data folder, throw him into the corridor of the garbage can! It's done (smooth delete!) )!

Linux directory and file permissions analysis

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.