What are the meanings of linux4-bit permissions?

Source: Internet
Author: User
I have been in touch with linux for a while, and a permission problem keeps me depressed. It cannot be found on the Internet (it is estimated that the keyword is incorrect). This is the 0777. what does the first 0 mean. I recently read a book (Linux and unixshell Programming Guide) and finally found the answer. What does 777 mean first...

I have been in touch with linux for a while, and a permission problem keeps me depressed. It cannot be found on the Internet (it is estimated that the keyword is incorrect). This is the 0777. what does the first 0 mean. I recently read a book (Linux and unix shell Programming Guide) and finally found the answer.
In linux, file permissions are divided into user permissions, group permissions, and other permissions.
Each item is divided into r (read) w (write) x (executable ). If you run ls-l in linux, the following permissions are displayed:
Java code
-Rwxr-xr-x 1 root 12 09-02 15:21 my_test.sh


"-" Indicates that the file type is not required. The first rwx is the permission of the owner, indicating that the owner (root) is readable (r) writable (w) and executable (x ). The second "-rx" indicates that the permissions of users in the same group are readable (r) and cannot be written (-) and executable (x ). The third indicates that the permissions of other users are readable and cannot be written and executable.
These numbers correspond to the permissions of the users who do not need them. The first 7 indicates the first rwx. of course, the second indicates the second and the third indicates the third.

The following describes what permissions 7 indicates.
If you change 7 to 2, it is 111. that's right, it corresponds to rwx. Of course, we all know that 1 indicates true, so the 7 permission is rwx. if the above my_test.sh is changed to 777, ls-l will display:
Java code
-Rwxrwxrwx 1 root 12 09-02 15:21 my_test.sh


On the other hand, you know what the number should be used for the above my_test.sh permission,
It should be 111101101 = 755
What does the first 0 mean:
0 in front of 0777 is originally called suid and guid.
Suid means that if a user sets this permission for his or her shell script, other users will also have the corresponding permissions of their owner when executing this script.
Guid indicates that the user executing the script has the permission of the user in the user group to which the file belongs.
Isn't it clear? here is an example:
Java code
-Rwxr-xr-x 1 root 12 09-02 15:21 my_test.sh

The above mysql_test.sh file permission is owned by the user (root) is 7. if suid is set, the permission of any other user is 7. if guid is set, the permissions of any user are 5.
How to set suid and guid:
When suid is set, the value 0 is changed to 4, and the value 0 is changed to 2 when guid is set. if both values are set, the value 6 is used.
Chmod 4777 mysql_test.sh

Author "chen498402552-163-com"

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.