In the previous use of the Windows system know that can set permissions for the file, then this permission is set, before the "Linux---User management command," mentioned in the system, the user is mainly to achieve resource sharing, the file permissions in the system is naturally also for the user to set permissions, If no system does not have a user, then set permissions is meaningless, the file permissions is completely "What a user has permissions for this file" can do what related to the file.
In the Linux system has the "everything is the file concept", of course, but also a lot of file types, but in the file permission settings are divided into "File permissions and Directory Permissions"
Linux system for files, file permissions can be divided into {readable (readable), abbreviated as "R",weitable (writable), abbreviated as "W",excutable (executable) "X"} three categories,
The user categories for the actionable files are {owner: Master "U", Group: Genus "G", Other: "O"} three categories
Permissions and operations for files in the system User:
-rw-r--r--. 1 root root 09:19 a.txt the second to tenth digits of the top ten are set to the right, respectively, the second to 4th bits are: U owner's permission, fifth to seventh is: G Group of permissions, eighth bit To tenth bit: O Other user's permissions. The third and fourth paragraphs, respectively, are root, indicating that the file's owner and owner group, in the file does not directly show the file o user, only in the permission settings to reflect.
How to manipulate permissions for file users:
R: Use the file viewing tool to get the contents of the file
W: can modify its contents
X: You can submit this file to the kernel to start as a process
How permissions are available for directory Users:
R: You can use LS to view the list in this directory
W: You can create files in this directory or delete files in this directory
X: You can use Ls-l to view the list of files in this directory, CD into such directory
Octal means file permission mode:
R=4,w=2,x=1, then the sum is 7, and because the user is divided into u,g,o three types of users can have permissions to file operations, each class of users can have 7 of the permissions of the file permissions, then the maximum permissions of the file permission is expressed as "777"
Chamod command: Change file mode bits
The "function" modifies the file permissions, modifies the permissions with the file as a reference, and enables its users to manipulate the file permissions,
Syntax
chmod [OPTION] ... "MODE ..." FILE: The way is to specify "XWR" to modify chmod [OPTION] ... Octal-mode file ...//This is modified by the "octal" mode to modify the files file permissions chmod [OPTION] ...--reference=rfile file ...//This mode is "refer to a file" to modify the specified file permissions
"Common Options"
-r,--recursive: Represents recursive modification of file permissions, often used when there are multiple sub-files in the directory
"Instance 1" adds W permission for the O user of the A.txt file, which is the main add x permission
[[Email protected] tmp]# lltotal 16-rw-r--r--. 1 root root 45 apr 22 09:19 a.txt-rw-r--r--. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 Apr 22 03:21 passwd-rw-r--r--. 1 root root 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 Apr 22 00:13 Yum.log[[email protected] tmp]# chmod u+x,o+w a.txt [[email protected] tmp]# lltotal 16-rwxr--rw-. 1 root root 45 apr 22 09:19 a.txt-rw-r--r--. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 apr 22 03:21 passwd-rw-r--r--. 1 root root 128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
Instance 2 The most commonly used octal method to set file permissions, modify b.txt file permission bits 444
[[email protected] tmp]# lltotal 16-rwxr--rw-. 1 root root 45 apr 22 09:19 a.txt-rw-r--r--. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 Apr 22 03:21 passwd-rw-r--r--. 1 root root 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 Apr 22 00:13 Yum.log[[email protected] tmp]# chmod 444 b.txt [[email protected] tmp ]# lltotal 16-rwxr--rw-. 1 root root 45 apr 22 09:19 a.txt-r--r--r--. 1 root root 25 Apr 22 11:08 B.txt-rw-r--r--. 1 root root 1336 apr 22 03:21 passwd-rw-r--r--. 1 root root 128&nbSp APR 22 08:40 TESTFILE-RW-------.  1 ROOT ROOT    0 APR 22 00:13 yum.log
Instance 3 references a file setting to specify file permissions,
Set permissions on the reference yum.log file permission bit b.txt a.txt and testfile [[email protected] tmp]# lltotal 16- Rwxr--rw-. 1 root root 45 apr 22 09:19 a.txt-r--r--r--. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 Root root 1336 apr 22 03:21 passwd-rw-r--r--. 1 root root  128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log[[email protected] tmp]# chmod --reference =yum.log b.txt a.txt testfile [[email protected] tmp]# lltotal 16- RW-------.  1 ROOT ROOT   45 APR 22 09:19 A.TXT-RW-------. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 Root root 1336&nbsP APR 22 03:21 PASSWD-RW-------. 1 root root 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
chown Command: Change file owner and group
"Features" Modify the file owner and the group, in some cases need to modify the owner of the file group, such as a script file needs a user to run, at this time only modify the file permissions is not satisfied.
Syntax
chown [OPTION] ... [OWNER] [: [GROUP]] File ...//indicates that the owner or group of the specified modified files can be changed to Chown [OPTION] ...--reference=rfile file ...//parameter modify the owner and group of the specified file
"Common Options"
-R,--Recursive: a generic group representing recursive modified files, often used when there are multiple sub-files in the directory
"Instance 1" modifies the owner of the A.txt file to Zhangsan user
[[EMAIL PROTECTED] TMP]# LLTOTAL 16-RW-------. 1 root root  45 APR 22 09:19 A.TXT-RW-------. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 Apr 22 03:21 PASSWD-RW-------. 1 root root 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 Apr 22 00:13 yum.log[[email protected] tmp]# tail -n 3 /etc/passwdzhangsan:x:501:501::/home/ zhangsan:/bin/bashlisi:x:503:503::/home/lisi:/bin/bashuser1:x:505:505:tell 110:/home/testuser1:/bin/tcsh[ [email protected] tmp]# chown zhangsan a.txt [[email protected] tmp]#  LLTOTAL 16-RW-------. 1 zhangsan root 45 Apr 22 09:19 A.TXT-RW-------.  1&NBsp;root root 25 apr 22 11:08 b.txt-rw-r--r-- . 1 root root 1336 apr 22 03:21 PASSWD-RW-------. 1 root root 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
Instance 2 modifies the B.txt file's owner and group are Zhangsan
[[EMAIL PROTECTED] TMP]# LLTOTAL 16-RW-------. 1 zhangsan root  45 APR 22 09:19 A.TXT-RW-------. 1 root root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root   ROOT 1336 APR 22 03:21 PASSWD-RW-------. 1 root    ROOT  128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log[[email protected] tmp]# chown zhangsan:zhangsan b.txt [[email protected] tmp ]# LLTOTAL 16-RW-------. 1 zhangsan root 45  APR 22 09:19 A.TXT-RW-------. 1 zhangsan zhangsan 25 apr 22 11:08 B.txt-rw-r--r--. 1 root root 1336 APR 22 03:21 PASSWD-RW-------. 1 root root     128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 Apr 22 00:13 Yum.log
Instance 3 copies the owner and group of the B.txt file to the Testfile file
[[EMAIL PROTECTED] TMP]# LLTOTAL 16-RW-------. 1 zhangsan root      45 APR 22 09:19 A.TXT-RW-------. 1 zhangsan Zhangsan 25 apr 22 11:08 b.txt-rw-r--r--. 1 root    ROOT     1336 APR 22 03:21 PASSWD-RW-------. 1 root root 128 apr 22  08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log[[email protected] tmp]# chown --reference=b.txt testfile [[email protected] tmp]# lltotal 16- RW-------. 1 zhangsan root 45 Apr 22 09:19 A.TXT-RW-------. 1 zhangsan zhangsan 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 apr 22 03:21  PASSWD-RW-------. 1 zhangsan zhangsan 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
Instance 4 recursively modifies the owner and host group of the file so that its test directory and sub-file are both Zhangsan
[[EMAIL PROTECTED] TMP]# LS -L TESTTOTAL 16-RW-------. 1 root ROOT   45 APR 23 08:25 A.TXT-RW-------. 1 root root 25 apr 23 08:25 b.txt-rw-r--r--.  1 ROOT ROOT 1336 APR  23 08:25 PASSWD-RW-------. 1 root root 128 Apr 23 08:25 TESTFILE-RW-------. 1 root root 0 apr 23 08:25 yum.log[[email protected] tmp]# ls -ld testdrwxr-xr-x. 2 root Root 4096 apr 23 08:25 test[[email protected] tmp]# chown -r zhangsan:zhangsan test[[email protected] tmp]# ls -ld testdrwxr-xr-x. 2 zhangsan zhangsan 4096 apr 23 08:25 test[[email protected] tmp]# ls -l teST TOTAL 16-RW-------. 1 zhangsan zhangsan 45 Apr 23 08:25 A.TXT-RW-------. 1 zhangsan zhangsan 25 apr 23 08:25 b.txt-rw-r--r--. 1 zhangsan zhangsan 1336 Apr 23 08:25 PASSWD-RW-------. 1 zhangsan zhangsan 128 Apr 23 08:25 TESTFILE-RW-------. 1 zhangsan zhangsan 0 apr 23 08:25 yum.log
"Instance 5" only modifies files passwd group is Zhangsan
[[EMAIL PROTECTED] TMP]# LLTOTAL 20-RW-------. 1 zhangsan root      45 APR 22 09:19 A.TXT-RW-------. 1 zhangsan Zhangsan 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 apr 22 03:21 passwddrwxr-xr-x.  2 ZHANGSAN ZHANGSAN 4096 APR 23 08:25 TEST-RW-------. 1 ZHANGSAN ZHANGSAN  128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 Apr 22 00:13 yum.log[[email protected] tmp]# chown :zhangsan passwd [[email PROTECTED] TMP]# LLTOTAL 20-RW-------. 1 zhangsan root 45 apr&nBSP;22 09:19 A.TXT-RW-------. 1 zhangsan zhangsan 25 Apr 22 11:08 b.txt-rw-r--r--.  1 ROOT     ZHANGSAN 1336 APR 22 03:21 passwddrwxr-xr-x. 2 zhangsan zhangsan 4096 Apr 23 08:25 TEST-RW-------. 1 zhangsan zhangsan 128 Apr 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
chgrp Command: Change group ownership
"Feature" modifies the genus group of files or directories
Syntax
CHGRP [OPTION] ... Group File ...//modify Filegroups
CHGRP [OPTION] ...--reference=rfile FILE: Specify a reference file to modify the specified file group
"Common Options"
-R,--Recursive: represents a group of recursive modified files, often used when there are multiple sub-files in the directory
"Instance" modifies a file belonging to a group
[[EMAIL PROTECTED] TMP]# LLTOTAL 20-RW-------. 1 zhangsan root      45 APR 22 09:19 A.TXT-RW-------. 1 zhangsan Zhangsan 25 apr 22 11:08 b.txt-rw-r--r--. 1 root zhangsan 1336 apr 22 03:21 passwddrwxr-xr-x. 2 zhangsan  ZHANGSAN 4096 APR 23 08:25 TEST-RW-------. 1 zhangsan zhangsan   128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log[[email protected] tmp]# chgrp root b.txt passwd testfile [[email PROTECTED] TMP]# LLTOTAL 20-RW-------. 1 zhangsan root 45 apr&nBSP;22 09:19 A.TXT-RW-------. 1 zhangsan root 25 apr 22 11:08 b.txt-rw-r--r--. 1 root root 1336 apr 22 03:21 passwddrwxr-xr-x. 2 zhangsan  ZHANGSAN 4096 APR 23 08:25 TEST-RW-------. 1 zhangsan root      128 APR 22 08:40 TESTFILE-RW-------. 1 root root 0 apr 22 00:13 yum.log
Umask command, you can view the file default permissions in the Linux system,
[Email protected] tmp]# umask0022
[Email protected] ~]$ umask0002
Administrative user default permissions bit 0022, meaning is the file default permission bit 666 to remove the X permission, means that in the creation of the normal file is the default permission bit 644, when the directory is created by default permission bit 755, the table in the creation of the file by default is not to give the file to execute (x) permissions by default if x permission then automatically + 1, the normal user creates the file permission bit 664 by default.
"Instance 1" Administrative user creates file and directory default permissions
[[email protected] tmp]# Touch Filenamelog[[email protected] tmp]# mkdir testfile[[email protected] tmp]# lltotal 4-rw-r-- R--. 1 root root 0 Apr 08:47 filenamelogdrwxr-xr-x. 2 root root 4096 Apr 08:48 testfile-rw-------. 1 root root 0 Apr 00:13 yum.log
"Instance 2" Normal user create file and directory default permissions
[email protected] ~]$ Touch Filename[[email protected] ~]$ mkdir directory[[email protected] ~]$ lltotal 4drwxrwxr-x. 2 Zhangsan zhangsan 4096 Apr 08:48 directory-rw-rw-r--. 1 Zhangsan zhangsan 0 Apr 08:46 filename
This article is from the "Perthon" blog, make sure to keep this source http://perthon.blog.51cto.com/10484057/1766946
Linux commands (+)---file Rights management commands