Very important! Relationship between Linux permissions and commands

Source: Internet
Author: User
Permissions are very important for a user account, because they can restrict the user's ability to read, create, delete, and modify files or directories! We will combine the management commands and file permissions of the file system to explain what commands can operate under what permissions! Pai_^ 1. What are the basic permissions for enabling users to access a directory as a "working directory:
    • Commands that can be used: commands such as CD to change the working directory;
    • Directory Permissions: You must have at least X permissions on this directory.
    • Extra requirement: If you want to use ls to check the file name in this directory, you still need the r permission for this directory.
2. What are the basic permissions for a user to read a file in a directory?
    • Available commands: such as CAT, more, less, etc.
    • Directory Permissions: You must have at least X permissions on the directory;
    • File permissions: You must have at least R permissions on the file!
3. Why can users modify the basic permissions of a file?
    • Available commands: such as nano or VI editor;
    • Directory Permissions: You must have at least X permissions in the directory where the file is located;
    • File permissions: You must have at least R and W permissions on the file.
4. What is the basic permission for a user to create a file?
    • Permissions required for a directory: You must have permissions W and X in this directory, with the focus on W!
5. What are the basic permissions for a user to access a directory and execute a command under the directory?
    • Directory Permissions: You must have at least X permissions in the directory;
    • File permissions: You must have at least X permissions on the file.
Example 1: when a user testuser can run the "CP/dir1/file1/dir2" command, what are the minimum permissions required for dir1, file1, and dir2? A: When executing CP, testuser needs to "be able to read the source file and write it to the target file !』 Therefore, please refer to the instructions on the second and fourth points above! Therefore, the minimum permissions for each file/directory should be: Dir1: requires at least X permissions; File1: at least the r permission is required; Dir2: requires at least W and X permissions. Example 2: The full name of a file is/home/student/www/index.html. the permissions for related files/directories are as follows: drwxr-XR-x 23 Root 4096 Sep 22/drwxr-XR-x 6 Root 4096 Sep 29/home drwx ------ 6 Student 4096 Sep 29/home/student drwxr-XR-x 6 Student 4096 Sep 29/home/student/www-rwxr -- r -- 6 Student 369 Sep 29/home/student/www/index.html could you tell testuser this account (not in the student group) can I read the file index.html? What about it? A: Although WWW and index.html have the permission to read testuser, the directory structure is read by the root directory layer, therefore, testuser can access/home, but cannot access/home/student/. Since no access to/home/student is allowed, index.html cannot be read! So the answer is "testuser won't read index.html content! How can I modify permissions? In fact, you only need to change the/home/student permission to a minimum of 711, or directly give 755! This is an important concept!

 

Reference: 3rd edition of laruence's Linux basic learning for Private food

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.