One, user owner, group owner, permissions
Each file in Linux has three properties that allow the user to control how the file is accessed.
When a file is created, the current user is the user owner of the file (that is, which user created the file), and the group owner is the primary group of the user, typically with the same name as the user. A normal user cannot change the file user owner, but the group owner can be changed (for example, NEWGRP can define the primary groups before learning).
The permissions of the file define how users of three different poles can use this file:
Two or three types of permissions
By knowing the owner of the user, the group owner, others have different permissions on the file, where each group of permissions is divided into rwx, labeled "-" indicates that this permission is not in the set of permissions. For example, rw-indicates that there is no X permission.
| Mark |
Permissions |
Description |
| R |
Read |
For files that indicate the ability to read the contents of a file, a list of files in the directory can be browsed for folder representations |
| W |
Write |
For file representations You can modify the contents of a file, for folder representations you can create and delete files |
| X |
Perform |
For file representations that can be performed (similar to the Windows EXE file), the folder representation can be entered in this folder. |
Three or three levels of access
Each file has three different sets of Read, write, execute permissions, respectively for the file owner (U), the group owner (G), and others (O).
When someone accesses a file, the system is accessed in the following order:
- Is the current user the file owner? If user rights are enabled.
- Is the current user a member of the group owner? If group permissions are enabled.
- If neither of the preceding permissions is enabled.
(i) Other person's authority test
[email protected]:~$ echo "hello" > /tmp/abc.txt[email protected]:~$ su - linux密码:$ echo "hello" >> /tmp/abc.txt-su: 1: cannot create /tmp/abc.txt: Permission denied$ ls -l /tmp/abc.txt-rw-r--r-- 1 cclove cclove 6 7月 14 18:57 /tmp/abc.txt
We first created the file/tmp/abc.txt with the Cclove user, then switched to the Linux user, appended the string to the/tmp/abc.txt file, but found no permissions. Then we use Ls-l to check, found that others can only read, cannot write, so can not modify their files.
(ii) Competence testing of common group members
First we look at the group owner permission for the Abc.txt file as read and write, which means that abc.txt can be modified as long as the members of the Cclove group. After we switched to Linux through the ID to look at, found that the Linux user's secondary group has cclove, which indicates that Linux in the Cclove group, the file has modify permissions.
Here to pay attention, Lao Mo by modifying the/etc/group file:
cclove : x : 1000 : linux
Put Linux into the Cclove last field, indicating that the user belongs to the Cclove group, and if there are multiple users, separate them with commas.
(iii) Permissions for symbolic link files
The link file is the shortcut created, and here Link_abc.txt is the shortcut to Abc.txt. We found that the permission is rwxrwxrwx, but actually it is linked to Abc.txt, so the permissions are the same as abc.txt.
Iv. Modifying file permissions
chmod ugoa +-= rwx filename
| Abbreviations |
Description |
| U |
User owner |
| G |
Group owner |
| O |
Other people |
| A |
Above three groups (all) |
| + |
Increase permissions |
| - |
Subtract permissions |
| = |
Set permissions |
| R |
Read |
| W |
Write |
| X |
Perform |
Cases:
Add the X permission to the file Abc.txt user owner, the group owner adds the W permission, and the other person removes the R permission.
V. Modifying the group owner of a file
Before old Mo temporarily modifies the user's primary group through NEWGRP, then creates the file with the modified group, but if the file has been created, there is nothing to do.
We need to use CHGRP to modify (change group):
chgrp GROUP file……
The purpose of this command is to change the group owner of a file to group and to modify multiple files at once.
Only the owner of the file can change the group to which the file belongs, and the user must be a member of the new group.
Let us analyze:
Create a file first, see if his group owner is Laomo, then see who owns the secondary group of the file owner user, view the group owner to modify file with Chgrp to Netdev, and then review the success.
The group owner who finally modified the file failed because the Laomo user is not a member of the music group, so it cannot be modified. If you want to change the administrator account can be changed.
Vi. Modifying the user owner of a file
This needs to be managed to operate, the normal user does not have permission to modify.
chown USER file……
Change the owner of the file to user.
Let us analyze:
The user owner who first looked at the file was Laomo, and then we modified it to the Me user with chown (Me is the new user created by Old MO), notice that to modify it with administrator privileges, the owner of the file is turned into me.
Linux Basics-11