In Linux, for data security, permission control is very important, in this case can be subdivided into two parts to understand his
Permission definitions
Each user of Linux belongs to a group and cannot be independent of the group. Linux file permissions need to define three entities ' permissions on it
- File owner
- The group where the files are
- Other groups
Owner
Typically the creator of the file, who created the file, becomes the owner of the file naturally
You can use the Chown "Change owner" username file name to modify the owner of the file, such as changing the owner of the Error.log to Enoch
Chown Enoch Error.log #更改error the owner of the. Log is Enoch Chown enoch:home error.log #更改error. Log owner and user group for Enoch and home Chown The user group for the. Home Error.log #更改error. Log is used for home# in the owners and user groups. Yes, but because many users prefer to use the decimal point, which can cause system errors, it is recommended to use ":"
Your group
When a user creates a file, the group where the file is located is the user group that the user is in.
You can use the Chgrp "change group" to alter the group in which the file is located
chgrp Home Error.log #修改文件的所在组为home
Other groups
Except for groups other than the group are other groups
Permission Description
When we use the command ls-l, it will show the corresponding permission to change the file or folder.
2 www www 4096 may 5:2 4096 may 5:wuyi wwwlogsdrwxr34096 Jul 4: wwwroot
The first column specifies the file permission description, which consists of 10 characters divided into four parts, using the WWW directory
[d] [rwx] [---] [---]
1 234 567 890
1: Whether this file is a directory or a file name where D represents the directory, if the file is-, more file information is as follows
d directory file. l Symbolic link (pointing to another file, similar to a shortcut under plague). s socket file. B -block device file, binary file. C -character device file. p Name the pipe file.
234: File owner's permissions, rwx and readable writable executable
R (read, reading): For a file, have permission to read the contents of the file, and for the directory, have permission to browse the directory. w(write, writes): For the file, with new, modified, delete the contents of the file permissions (do not include the deletion of the file); For the directory, with new, deleted, modified, Permission to move files within the directory (regardless of the file's permissions can be deleted). X (Execute, execute): For the file, it has permission to execute the file, and for the directory, the user has permission to enter the directory (you can use the CD command to enter the directory).
567: File permissions for all groups,---represents no permissions
890: There is no permission here except for the owner and all users outside the group
Modify Permissions
The command to modify permissions is chmod, and the way to change permissions is divided into two
1. Number Change Permission method
Linux file basic permissions only nine, respectively, is onwer,group,other three kinds of identities, so we can use numbers to represent permissions, where
4 W 2 1
Each identity setting permission is an accumulation of numbers, such as setting the Error.log file to everyone with rwx permissions, then
chmod 777 Error.log
Because [-rwxrwxrwx] is actually [4+2+1][4+2+1][4+2+1] is 777. If we change the permission to [-rwxr-xr--] then [4+2+1][4+0+1][4+0+0] is 754
2. Symbol Change method
The symbolic change method is actually to set permissions on different entities, in which we can only understand the meaning of the three parts
chmod |
U |
+ (Join) |
File or directory |
G |
= (set) |
O |
A |
-(remove) |
Give a few examples to illustrate, set the user to Error.log have rwx permissions, the group and other groups have RX permissions.
chmod U=rwx,go=rx Error.log
Set the user to Error.log have rwx permissions, the group has the RX permission, the other groups have R permissions
chmod u=rwx,g=rx,o=r error.log
Out of the executable permissions for all users
chmod a-x error.log
Differences in Permissions
Linux File Permissions settings