File Permission Management in CentOS
Reference laruence private dish: http://vbird.dic.ksu.edu.tw/
The first thing is a pitfall: When I was using an ftp server of my company a few days ago, I ran the code in the root directory.
sudo
chmod
777/-R
Duang: the system crashed. Root cannot be entered, and various problems are followed. There are many ways to remedy the problem, but none can. Finally, we had to reinstall the system. Fortunately, there is nothing important.
The cause of this problem is that you only know that you have set the 777 permission for file permission management. This eventually leads to an unreachable error. It can only be said that people are killed with only half-knowledge Knowledge knowledge.
The landlord decided, so he re-learned the management of file permissions.
First, the command for permission management:
chgrp
//
Set Group Permissions
chown
//
Set permissions for users and groups
chmod
//
Set read/write execution Permissions
First, check the file permissions in the/root directory:
[root@localhost~]
#ls-llinstall.log
-Rw-r --. 1rootroot37332 August 21: 11
install
.log
Print the first part of the information:
-rw-r--r--
//
1st bits indicate the file type, which indicates a common file. If it is d, it indicates a directory. If it is l, it indicates a link.
2-4 bits indicate the permission of the object owner. rw-indicates that the object owner has the read and write permissions.
5-7 bits indicate the permissions of the group to which the file belongs. Here, r -- indicates that the Group has read-only permissions.
8-10 bits indicate the permissions of users and groups other than users and groups. Here, r -- indicates that other users and groups have read-only permissions.
It can be expressed as follows:
type
usergroupother
Other user groups
Part 2: 1 indicates that one document link node exists.
Part 3: rootroot indicates that the user of the file is root and the group to which the file belongs is root.
Part 4: 37332 indicates that the file size is 37332 bytes.
Part 5: December 21, November 30 represents the time
Part 6:
install
. Log indicates the file name.
Complete File Information Format:
File Type File Permission file link node user group file size last Edit Time file name
Use the permission management command to change permissions:
chgrp
Change the file group:
[root@localhost~]
#chgrptestinstall.log
[root@localhost~]
#ls-llinstall.log
-rw-r--r--.1root
test
3733211-month 3021: 11
install
.log
The file group is
test
, So
test
Group member Pairs
install
The. log file has the read permission.
Chown:
[root@localhost~]
#chowntestinstall.log
[root@localhost~]
#ls-llinstall.log
-rw-r--r--.1
test
test
3733211-month 3021: 11
install
.log
The file owner is
test
.
test
User pair
install
The. log file has read and write permissions.
Chown simultaneously changes users and groups:
[root@localhost~]
#chownroot:rootinstall.log
[root@localhost~]
#ls-llinstall.log
-Rw-r --. 1rootroot37332 August 21: 11
install
.log
By executing,
chown
User: groupfilename: both users and groups are modified.
Chmod
R indicates that the file is readable, w indicates that the file is writable, and x indicates that the file is executable.
chmod
Command Format:
chmod
u=rwx,g=rwx,o=rwxfilename
//u
Indicates the user, g indicates the group, and o indicates other
chmod
+xfilename
//
Add executable permissions
chmod
-xfilename
//
Minus the executable permission
[root@localhost~]
#ls-llinstall.log
-Rw-r --. 1rootroot37332 August 21: 11
install
.log
[root@localhost~]
#chmodu+x,g+x,o+xinstall.log
[root@localhost~]
#ls-llinstall.log
-Rwxr-xr-x.1rootroot37332 November 21: 11
install
.log
//
Added the executable permission.
[root@localhost~]
#chmod-xinstall.log
[root@localhost~]
#ls-llinstall.log
-Rw-r --. 1rootroot37332 August 21: 11
install
.log
//
Reduced executable permissions
Change the permission in numeric mode:
Rwx is represented by, 1,
4+2+1=7
//
All Permissions
4+2=6
//
Readable and writable
4+1=5
//
Readable and executable
2+1=3
//
Writable and executable
chmod
777filename
//
Users, groups, and others are readable, writable, and executable.
chmod
755filename
//
User readable, writable, executable, group, and other readable, executable
[root@localhost~]
#chmod777install.log
[root@localhost~]
#ls-llinstall.log
-Rwxrwxrwx.1rootroot37332 August 21: 11
install
.log
//
Restore original Permissions
[root@localhost~]
#chmod644install.log
[root@localhost~]
#ls-llinstall.log
-Rw-r --. 1rootroot37332 August 21: 11
install
.log
Differences between file and directory permissions:
file
rwx
//
Read/write execution
R read indicates that the file content can be read and written.
W write the content that can be edited, added, or modified for the file (but the file cannot be deleted)
The x execution file can be executed as a binary file. If the execution is successful or not, it depends on the file content.
dir
rwx
//
Read/write execution
R indicates that files can be read and written.
W create a new file and directory
Delete existing files and directories
Change the name of a file or directory
Move a file or directory to another directory
X indicates that files can be accessed.