Linux File System Permissions

Source: Internet
Author: User
Linux operating system file system permissions-general Linux technology-Linux technology and application information. For more information, see the following section. In Linux, each file and directory has access permission to determine who can access and operate files and directories.

Use the ls command of the-l parameter to display the detailed information of the file.

Ls-l

The following columns are displayed:

File type and permission hard link count file owner file group file size created or recently modified name for symbolic link files, the displayed file name is followed by "->" and the Referenced File Path Name.

For device files, the "file size" field shows the master and secondary device numbers, rather than the file size. The total number of blocks in the directory is displayed at the beginning of the long format list, which contains indirect blocks.

In the information displayed by the ls-l command, the start is a string consisting of 10 characters. The first character indicates the file type, which can be one of the following types:

-Common files
D directory
L Symbolic Link
Block B Device Files
C character Device File
S interface file
P Pipeline

The following nine characters indicate the object access permissions. They are divided into three groups, each with three characters. The first group indicates the permissions of the file owner, the second group indicates the permissions of users in the same group, and the third group indicates the permissions of other users. The three characters in each group indicate the read, write, and execute permissions for the file.

2nd ~ Each three of the 10 characters is a group. The three characters on the left indicate the owner permission, and the three characters in the middle indicate the permissions of users in the same group as the owner, the three characters on the right are the permissions of other users. These three groups contain nine characters, which indicate the following meanings:

-No permission is set.

R (Read): For a file, you have the permission to Read the file content; for a directory, you have the permission to browse the directory.

W (Write): For a file, you have the permission to add or modify the file content. For a directory, you have the permission to delete or move files in the directory.

X (eXecute): For a file, you have the permission to eXecute the file. For a directory, you have the permission to enter the directory.

S or S (SUID, Set UID): an executable file can be used with this permission to obtain the privilege to access all the system resources that the file owner can use. Pay attention to files with SUID permissions. Hackers often use this permission to attach SUID to the root account owner and open a backdoor in the system for future use. The suid bit does not have any effect on the directory. You can provide a command that can only be used by the root user to normal execution. For example, the command/sbin/ifconfig should be noted, when a common user wants to execute a command with suid set, the full PATH/sbin/ifconfig must be added, which is caused by a different environment than the root user's PATH.

S or S (SGID, Set GID): Set on the file, the effect is the same as SUID, except that the file owner is changed to a user group, this file allows you to access system resources that can be used by the entire user group. The sgid is used to set the group to which all newly created files belong to the directory, regardless of the Creator's group.

T or T (Sticky): Set the flag bit (left in memory, not swapped out ). If the file is a directory, the files in the directory can only be deleted by the Super User, directory owner, or file owner. If it is an executable file, after the file is executed, the pointer pointing to its body segment remains in the memory. In this way, the system will be able to mount the file more quickly when you execute it again. The/tmp and/var/tmp directories allow all users to temporarily access files. That is, each user has full permissions to access the directory to browse, delete, and move files. The object created in this directory can only be renamed or deleted by the owner. Other users do not have the permission to delete the objects of other users even if they have full access permissions.

Currently, the pasting bit is rarely used. However, for a directory like/tmp, it makes sense to store temporary files in the entire system. Rwxrwxrwx is enabled for a directory even if all its permissions are enabled. Unless the directory owner and root user have the permission to delete it, other users cannot delete this directory. The general purpose is to open the permissions of a folder and share the file, like the/tmp directory.

Because SUID, SGID, and Sticky occupy the position of x, they are case sensitive. When both the execution permission and SUID, SGID, and Sticky are enabled, the permission indicates that the characters are lowercase:

If the execution permission is disabled, the characters are capitalized:

There are three different types of users who can access files or directories: file owners, users in the same group and other users. The owner is generally the creator of the file. The owner can allow users in the same group to access files and grant the file access permission to other users in the system. In this case, every user in the system can access the files or directories owned by this user.

Each file or directory has three groups of access permissions. Each group is represented by three digits, which are the read, write, and execution permissions of the file owner; the read, write, and execution permissions of users in the same group as the owner; the read, write, and execution permissions of other users in the system. When you use the ls-l command to display detailed information about a file or directory, the leftmost column lists the file access permissions.

[Root @ localhost ~] # Ls-lih
Total 104 K
2408949-rwxr-xr-x 1 root 7 04-21 12:47 lsfile. sh
2408830 drwxr-xr-x 2 root 4.0 K 04-21 mkuml-2004.07.17
2408260 drwxr-xr-x 2 root 4.0 K 04-21 mydir
2408258 lrwxrwxrwx 1 root 7 04-21 sun001.txt-> sun.txt
2408263-rw-r -- 2 root 11 04-20 14:17 sun002.txt
2408263-rw-r -- 2 root 11 04-20 sun.txt

Explanation:
Field 1: inode
Field 2: file types and permissions;
Field 3: Number of hard links;

Field 4: file owner;
Field 5: the group to which it belongs;
Field 6: file or directory size;
Field 7 and Field 8: Last access or modification time;
Field 9: file name or directory name

Permission bit

Each file or directory has a group of 9 permission bits, each of which is divided into one group. They are respectively sovereign Limited (with three locations) user Group Permissions (three locations) and other user permissions (three locations ). For example, in rwxr-xr-x, we can check whether there are nine locations. These nine permission locations control the permissions of the file owner, user groups, and other users.

The permission bits of Linux files or directories are controlled by nine permission bits, each of which is a group of three

Reading, writing, and execution of file owners, reading, writing, and execution of user groups, and reading, writing, and execution of Other users (Other;
File owner: Read r, write w, execute x
User Group: Read r, write w, execute x
Other users: Read r, write w, execute x

If the permission bit is unreadable, writable, or unexecutable, it is represented.

You can understand the read, write, and execute permissions of common files as follows:

Readable: it means we can view and read it;
Writeable: indicates that the permission can be modified or deleted (however, the permission to be deleted or modified is controlled by the permission in the parent directory );
Executable: it means that a file can be run, such as a binary file (such as a command) or a script (which should be interpreted and run with a script interpreter ).

To view the object properties, use the ls-l file. To view the directory properties, use the ls-d directory.

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.