Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
For linux file permission explanation, go to a directory. If ls-l is executed, all files under the directory will be displayed. (the word "& quot; file & quot;" is used here to indicate files and folders).: a total of 7 columns of information, including [permission], [number of links], [owner], [group], [size],... for linux file permission explanation, we enter a directory. executing ls-l will display the details of all the files under the Directory (here, the word "archives" stands for files and folders.: a total of seven columns of information, including [permission], [number of links], [owner], [group], [size], [last modification time], [name]. this article only describes [permissions], [owners], and [groups] in detail. because Linux is a multi-user multi-task system, many people may use this host at the same time. in order to consider the privacy of each person and the work environment that everyone prefers, therefore, the role concept is very important. there are three concepts. 1) Archive owner (user): The creator of the archive. 2) Group: the group to which the archive belongs. 3) others: users other than users and groups. let's take a look at the [permission] column, which has a total of 10 digits and can be divided into four sections. the 1st bits indicate the file type, '-' indicates that this is a regular file, and 'd' indicates that this is a folder. (There are other uncommon ones, such as 'L', 'C', 'B', 'P', and 'S', which are not explained here .) 2 ~ 4. the three digits indicate the read/write/execute permissions of the user. 5 ~ 7 these three represent the read/write/execute permissions of the group. 8 ~ 10 these three represent the read/write/execute permissions of others. if it is readable/written/executed, it is represented by the letter r/w/x. If it is not readable/written/executed, it is represented. read/write/execute is interpreted as follows (excerpt from Baidu Library): For Files: (the following test of file permissions is completed when the upper-level directory permission is 777: indicates that the content of the copied file can be read and written: indicates that the content of the file can be modified and executed: indicates that the file can be operated only by other parsing programs: only the read permission can read and copy the file. the file content cannot be rewritten. the permission to delete and move the file is determined by the permission of the upper-level Directory, if the upper-level Directory has the permission to delete and move, you can delete and move it. Only writable: If you have only writable permission but no read and execution permission, you cannot read or modify the content of the file or execute the file, and cannot copy the file, the permission to delete and move the file is determined by the permission of the upper-level Directory. Only executable: the file content cannot be read or rewritten only when the executable permission is available, and the file cannot be copied. it does not seem to be executed as a script, the permission to delete and move the file is determined by the permission of the upper-level Directory. Therefore, you must have the write permission on the file, both readable and writable, and the execution permission on the file. you must have both readable and executable permissions. For a directory: (the following test of directory permissions is completed when the involved file permissions are 777.) readable: lists the attributes of files and subdirectories in the directory itself and in the directory, view only properties (ls) writable: you can add and delete files and directories to the directory. execute: you can enter this directory, you can read the file content under the Directory or rewrite the file content (when the file permission permits) only readable: the read permission of the directory only allows us to read the directory, to obtain a list of all file names in the directory, you cannot add or delete files or directories, or read or modify the content of files in the directory. Only writable: If you only have the write permission, you cannot add or delete files or subdirectories to the Directory, including copying and moving. To modify the file content in a directory, not only the write permission of the directory, but also the execution permission of the Directory. Only executable: You do not have the read and write permissions on the directory, but only the execution permission. you can also read and rewrite the contents of the files in the Directory (as long as you confirm that the file exists in this path ); do you not need the write permission for the directory? Of course not. if you do not have the write permission, you cannot add or delete files or subdirectories to or from the directory, including copying and moving files and subdirectories. It can be seen that these three permissions are often used together. for example, for a directory, only the r permission may have no effect. generally, r and x must be provided at the same time (without x, r cannot enter the directory, and r is almost useless). for files, it is often useless if there is only w but no r. it still cannot be written and the original content of the file cannot be read. how can we add, delete, and modify the content. the user, group, and others mentioned above are not specific definitions. combined with the r/w/x permissions, an actual model is built, which seems easier to understand. if the problem persists, you may want to correct it. assume that four people, A, B, C, and D, share A four-bedroom, one-bedroom house outside the university, which can be considered as A general upper-level Directory, name it home. the rooms of the four persons are respectively A, B, C, D. the shared space such as the living room, bathroom, and kitchen is E. (1) Four people have ownership of their room. they are the owner of the room and usually have all permissions. Therefore, for room (directory), its properties may be like this --> dr Wx ------ user (A) group (A, each user is attached to at least one group, its main group) (2) The four are brothers of the 602 dormitory of the university, then we create A new group named dorm602 and add A, B, C, and D to this group. then, the permissions for E in this public area may be like this --> drwxrwx --- user (root) group (dorm602 ). in this way, the four persons A, B, C, and D of dorm602 have read, write, and execute permissions on E. (3) the relationship between A and B, C, and D is very good. you can also come in to my bedroom. it's so good that you can use anything, directory A permission may be set to --> drwxrwx --- user (A) group (dorm602 ). (4) A is really A good talker. he does not need A private space at all, except B, C, D. Other outsiders (for example, B's classmates come on A day) you can also visit his house, Yes, but you don't want others to touch his things. the permission of directory A can be set like this --> drwxrwxr-x user (A) group (dorm602 ). we can see that the others permission is r-x, that is to say, you can enter my house (x), and you can view anything in my room (r) at will ), but you cannot touch them (w ). similarly, we also use this example to look at the problem that directory rx should be provided at the same time and file rw should be provided at the same time. (5) now A is talking to B, C, and D. You can see that our relationship is so good, but you can't go into my house. then the permission is set as --> drwxrw ---- user (A) group (dorm602 ). as a result, it seems to be generous. In fact, there is no ridicule left. I don't have to grant the x permission. what if rw is used... well, since I am not allowed to enter it, I will check it at the door, so B tries to execute ls-l A/in the home directory. if there is A directory aaa in the house of, there is a file bb B, then you will probably get the result: d ?????????????? Aaa -?????????????? Bbb is reasonable, isn't it? Even if you have the r permission and cannot go into the house, you will probably be able to see what is in the room and the specific situation of things. (6) What if so --> drwx -- x --- user (A) group (dorm602 ). that is equivalent to saying that you can enter our house, but you have to hide your eyes. OK, the House can enter, but you don't know anything in it. it's impossible for you to move something in the house. so cd A actually enters Directory A, but if you ls it, sorry, the system prompts that you have no permission. (7) Sometimes we create a new file in a directory and prompt that we do not have the permission. what is the problem. this is like A thing of B that wants to be put in A's room. to achieve this, the permission of directory A can be like this --> drwx-wx --- user (A) group (dorm602 ). now A file ccc of B can be placed in room A. Note that the r of the group permission of directory A is not required, Wx is indispensable. (8) we can see that most of the above examples are using directories, because we should better accept the concept of read and write permissions for files. let's talk about the rw problem mentioned above. for files, only w permissions are often useless and cannot be written. r usually needs to carry. for example, if A has A file computer in the room, A Sets the file permission to --> d-wx ------ user (A) group (). if one day A finds that the CPU performance of his computer is too poor and wants to change A new CPU for his computer, of course, he has the right to perform this operation (w), but no r, so A can only close his eyes and assemble the new CPU into the computer. Obviously, this w operation won't succeed. without the r permission, he may not be able to open the lid of the computer, mei Chaofeng's eye-closed fight is so powerful that it can only exist in martial arts novels, right? ^. of course, for masturbation, A can still boot and play with the computer due to the permission of x, although it is relatively slow. here is an example. Er, group, and others should have some specific impressions! I have an understanding of these read and write permissions, user and group, and the purpose of this article is achieved. Finally, I attached the command to set permissions. chgrp: change the group to which the archive belongs. command format: chgrp groupname filename. of course, the group name must exist. II. chown: changed the archive owner. command format: chown username filename. similarly, the user name also needs to exist. in fact, chown contains the chgrp function, which is very flexible: chown username filename // only sets user chown username: groupname filename // user & group and sets chown at the same time: groupname filename // Set only group. ':' available '. '. 'The character may be confusing, so ':' is recommended. chmod: There are two ways to change the r/w/x permission: numbers and symbols. the weights of r, w, and x are 4, 2, and 1 respectively, so we can use three numbers to represent the permission table, for example, rwx ------ is 700, rwx --- r -- 704,-wx -- xrwx is 317. in this way, two methods can be used for chmod. This command is flexible and can be used as an example. number: it is easy to write, but the disadvantage is that it is not intuitive and it is not convenient to set the number locally. chmod 777 filename letter: this usage is very flexible, where u, g, o, a represent user, group, others, all. chmod u = rwx, go = rx filename chmod u = wx filename chmod g + x filename chmod a + w filename chmod + w filename
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.