File Permissions in Linux

  • Talking about file permissions, the first thing to know is to understand the concept of file owner.

  Concept of file owner, user group, others. The concept of file owners is easy to understand, and one of the most useful functions of user groups is data sharing for team work. In a user group, files created by file owner A can be set to be visible to group member B, but invisible to outsiders. Of course, A can also set his own "private" file. In other words, that is, things are mine, and I can show you to people in a circle. It’s not that I don’t give anything from a circle, and I don’t give things that are private to people in the circle. For people outside the circle is other people.

  • After logging in to Linux with root privileges and executing: ls -al, many lines appear. Here we focus on the first ten characters, to be precise, the second to tenth characters.

  For example: "-rw-rwxr--". The first character represents the file type, which is not detailed here. The second through fourth ("rw-") are the permissions of the owner of the file; the fifth through seventh ("rwx") are the permissions of the user group described in the file, and the remaining three ("r--") are the permissions of others Permissions for this file. Among them, "r", "w", and "x" represent readable, writable, and executable permissions, respectively.

  chgrp: Change the user group to which the file belongs;

  chown: change the file owner;

  chmod: change the permissions of the file;

As for the usage of these three, you can use the command: man plus the above command to query. It's worth being extra careful here: when you copy a file, the properties of the new file are unchanged. What do you mean? After you copy file 1 into file 2, the owner and user group of file 2 are the same as file 1. At this time, you give file 2 to another user. At this time, the owner and user group of the file must be modified. Otherwise, the new user cannot operate on file 2.

  • Permission meaning

   r (read): The actual content of this file can be read, such as reading the text content of a text file, etc.;

  w (write): You can edit, add or modify the content of the file, but you cannot delete the file itself ;

  x (execute): The file has permission to be executed by the system.

In other words, r and w are the right to operate on the contents of a file or directory, and x represents whether the user can enter the directory, which is called the working directory .

User A has "rwx" permission to a directory, and there are files belonging to another user B and another user group B in this directory, then A can delete the file, a simple one: your things are in my home, I don't If the law is opened, I can always throw it out.

Ref:

"Brother Bird Linux Private Kitchen, Basics (Third Edition)"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325058719&siteId=291194637