Write in front
We all know that Linux
is a multi-user, multi-tasking system, which is also its best feature, it is possible to have a lot of people working on the system, so do not force shutdown , at the same time, in order to protect everyone's privacy and work environment, For a document (file, directory), the Linux
system defines three identities, namely owner (owner), Group (group), others (others), each identity and three kinds of permissions, respectively, is readable (readable), writable (writable), executable (excutable).
Document properties
ls -al --full-time
ll
You can view all the properties of a file or directory by using a command, or a shorthand for this command. As follows:
As you can see from above, each row has 7 columns, namely:
- First column
A total of 10 bits, the 1th digit represents a document type, d
represents a directory, represents a -
file, represents a l
linked file, represents d
a device that can be randomly accessed, such as a USB flash drive, etc., c
indicating a disposable read device, such as a mouse, keyboard, etc. After 9 bits, in turn corresponds to three kinds of identities have the rights, the identity order is: Owner, group, others, the order of permissions are: readable, writable, excutable. such as: -r-xr-x---
the meaning of the current document is a file, the owner can read, executable, the same group of users, readable, writable, other people do not have any permissions .
- Second column
Indicates the number of links
- Third column
Represents the owning person
- Fourth column
Indicates the owning group
- Fifth Column
Indicates the document capacity size, in bytes
- Sixth column
Indicates when the document was last modified, not when the document was created.
- Seventh column
Represents the document name. With Dot (.) The beginning is the hidden document
Change owner (owner) Location
etc/passwd
Note: You must be an account that already exists in this location. That is, the /etc/passwd
owner of a record can change.
Grammar
chown [-R] [帐号名称] [文件或目录]chown [-R] [帐号名称]:[群组名称] [文件或目录]
Note: This command can also change the document group by the way, but it is recommended to use the chgrp command to change the document group.
Options
-R recursive change, that is, all files (folders) in the secondary directory must be changed.
Usage
chown daemon test
Change Folder Test account is daemon.
chown daemon:root test
Change Folder Test group to root.
chown root.users test
Change Folder account is root, group is users
chown .root test
Change group as root individually
Note: Although you can also add a decimal point between the owner and the group (.), but in order to avoid some students named in the DOT, it is recommended to use the colon ":" to separate owners and groups, to avoid miscalculation.
Change group Location
etc/group
Note: All groups can be viewed from here
Grammar
chgrp [-options] [群组名] [文档路径]
Note: For options, you can man chgrp、info chgrp、chgrp --help
query for detailed usage by waiting for commands.
Usage
chgrp -R users test
test
the group that changes the folder and all its sub-files (folders) is users
.
Note: The group name is not in the location, will be an error invalid group
.
Change permissions
Linux documents have three basic permissions, respectively read/write/execute
, plus owner/group/others
nine identities. There are 2 ways to change permissions, namely, symbolic and digital .
Symbolic method
Using U,g,o to represent three identities, a for all identities, three permissions using R, W, x respectively, using + 、-、 = for operation behavior, respectively
Grammar
Set Permissions (=)
The permission to change the catalog test is readable, writable, and executed by anyone.
chmod u=rwx,g=rwx,o=rwx test 或chmod ugo=rwx test 或chmod a=rwx test
Remove Permissions (-)
Remove directory test Execution permissions
chmod u-x,g-x,o-x test 或chmod ugo-x test 或chmod a-x test
Note: Execute permissions (x), the directory is just another user can CD test become working directory.
Add permissions (+)
Add directory Test Execution permissions
chmod u+x,g+x,o+x test 或chmod ugo+x test 或chmod a+x test
Note: It is very familiar, if we have finished writing a shell file test.sh, we have chmod a+x test.sh
added file execution permissions.
Digital method
As the name implies, is the use of numbers to represent permissions, R,w,x, respectively, 4,2,1. Three kinds of permissions accumulate to obtain an identity permission.
The permissions to set the directory test are readable, writable, and executed by anyone.
The permission to set the directory test is readable and writable by anyone.
Give a shell file test.sh executable permissions, the owner can read, write, execute, group accounts and other people can read and execute.
Note: There is no way to find the digital method is more simple AH!!!
File and Directory Permissions differences
Document permissions are significantly different for files and directories
File
For the contents of the file
- Readable can read the actual contents of the file
- Writable can edit, add, or modify the contents of the file
- Executable has permissions that can be executed by the system
Note: With W permissions can not delete files, delete files is the scope of directory permissions Control!!! Remember that file permissions are for file content .
Directory
For the file object in this directory
- Readable has the permission to read the directory structure manifest, that is, the ls command can be used to query the directory list.
- Writable has the ability to change the directory structure manifest to create, migrate, delete, and rename files in that directory.
- Executable has permission to enter the directory, which can be transferred to the working directory via the CD command.
Note: From the above can be obtained, open Directory for anyone to browse, at least need to give r
or x
permission. Read the contents of the directory file, requiring at least directory permissions x
and file permissions r
.
Summarize
Linux
Each document can be assigned permissions for three identities, change file rwx
chgrp
groups, command change file chmod
permissions, chown
change file owner, then remember to use the document permissions to protect the security of the data Oh .
Detailed description of Linux document properties, owners, groups, permissions, differences