To view file permission statements:
In terminal input: Ls-l xxx.xxx (xxx.xxx is the file name)
Then there will be similar messages, mostly these:-rw-rw-r--
A total of 10 digits
Which: the front one-represents the type
The middle three rw-represents the owner (user)
Then those three rw-represent groups (group)
The last three r--represent others (other).
And then I'll explain the 9 digits in the back:
R indicates that a file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
-Indicates that the appropriate permission has not been granted
Now it's time to talk about modifying file permissions.
In Terminal input:
chmod o W xxx.xxx
Give other people permission to write xxx.xxx this file
chmod GO-RW xxx.xxx
Represents the deletion of read and write permissions for groups and others in xxx.xxx
which
U on behalf of owner (user)
G represents the group where the owner resides
O stands for others, but not u and g (other).
A represents all people, including U,g and O.
R indicates that a file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
Where: Rwx can also be replaced by numbers
R------------4
W-----------2
X------------1
-------------0
Let's go:
Represents the Add permission
-Indicates delete permission
= indicates a permission to make it unique
When we all understand the above, then we often have some of the following permissions are easy to understand:
-RW-------(600) Only the owner has read and write permissions
-rw-r--r--(644) Only the owner has read and write permissions, and the group and other people only have Read permissions
-RWX------(700) Only the owner has read, write, execute permissions
-rwxr-xr-x (755) Only the owner has read, write, execute permissions, groups and other people only read and Execute permissions
-rwx--x--x (711) Only the owner has read, write, execute permissions, groups and other people only execute the permissions
-rw-rw-rw-(666) Everyone has access to read and write
-RWXRWXRWX (777) Everyone has access to read and write and execute
Linuxfile and Directory access permissions settings
Usechmodand numbers to change the access rights of a file or directory Permissions for files and directories are represented by the rwx three characters to represent the permissions of the owner, user group, and other users. Sometimes, characters seem to be too cumbersome, so there is another way to represent permissions in numbers, and only three numbers are required. R: Corresponding value 4 W: corresponding value 2 x: Corresponding value 1-: The key of the corresponding value 0 digital setting is the value of mode, at first many beginners will be confused, actually very simple, we will rwx as a binary number, if there is 1 said, there is 0 said, then rwx r-x R- can be represented as: 111 101 100 then convert each of its three bits into a decimal number, which is 754. For example, we want to let a.txt this file permissions for: The same group of users other users can read Yes Yes is writable is executable then, we first get permission string according to the above table: rw-rw-r--, then convert to binary number is 110 110 100, and then every three bits converted into a decimal number, you have to To 664, so we execute the command: [[email protected] ~]# chmod 664 A.txt In accordance with the above rules, rwx together is 4 2 1=7, a rwxrwxrwx permission to open the file, the value is expressed as 777 , and the file "---------" with a completely non-open permission is represented by a number of 000. Here are a few examples:-rwx------: equals the number represents 700. -rwxr-r--: equals the number represents 744. -rw-rw-r-x: equals the number represents 665. Drwx-x-x: equals the number represents 711. DRWX------: equals the number represents 700. In text mode, you can execute the chmod command to change permissions on files and directories. Let's take a look at the ls-l in the directory: [[email protected] ~]# ls-l Total usage 368-rw-r--r--1 root root 12172 August 23:18 conkyrc.sample DRW Xr-xr-x 2 root root 48 September 4 16:32 desktop-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6 drwxr-xr-x 2 root ro OT 48 August 22:25 mymusic-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth0-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo drwxr-xr-x 2 root root 48 September 6 13:06 VMware can see of course file C The permissions for the Onkyrc.sample file are 644, then the permissions for this file are changed to 777. Execute the following command [[email protected] ~]# chmod 777 Conkyrc.sample and then ls-l look at the results after execution: [[email protected] ~]# ls-l Total usage 368-r wxrwxrwx 1 root root 12172 August 23:18 conkyrc.sample drwxr-xr-x 2 root root 48 September 4 16:32 desktop-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6 drwxr-xr-x 2 root root 48 August 22:25 mymusic-rwxr-xr-x 1 root root 9776 November 5 08:08 Net.eth0-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1-rwxr-xr-x 1 root root 512 November 5 08:08 net.lo drwxr-xr-x 2 root Root 48 September 6 13:06 VMware can see that the permissions for the Conkyrc.sample file have been modified to rwxrwxrwx if you want to add special permissions, you must use a 4-digit number to represent it. The corresponding value of the special permission is: s or S (SUID): Corresponds to the value 4. s or S (SGID): corresponds to the value 2. T or T: corresponds to the value 1.
Modifying file permissions in the same way can be used for example:
[Email protected] ~]# chmod 7600 conkyrc.sample [[email protected] ~]# ls-l Total usage 368-rws--s--t 1 root root 12172 August 15 2 3:18 conkyrc.sample drwxr-xr-x 2 root root 48 September 4 16:32 desktop-r--r--r--1 root root 331844 October 21:08 libfreetype.so .6 Drwxr-xr-x 2 root root 48 August 22:25 mymusic-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth0-rwxr-xr-x 1 root root 9 776 November 5 08:08 net.eth1-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo drwxr-xr-x 2 root root 48 September 6 13:06 VMware join want to modify it once Permissions for all files in a directory, including file permissions in subdirectories, are also modified to use the parameter-R to initiate recursive processing. For example: [[email protected] ~]# chmod 777/home/user Note: Only set the/home/user directory permission to rwxrwxrwx [[email protected] ~]# chmod-r 777/home/ User note: Indicates that the permissions for the entire/home/user directory and its files and subdirectories are set to RWXRWXRWX
Use the command chown to change the ownership of a directory or file Files and directories can not only change permissions, their ownership and user groups can also be modified, and set permissions similar to the user can be set through the graphical interface, or execute the chown command to modify. Let's take a look at the directory first ls-l: [[email protected] ~]# ls-l Total usage 368-rwxrwxrwx 1 root root 12172 August 23:18 conkyrc.sample drwxr- Xr-x 2 root root 48 September 4 16:32 desktop-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6 drwxr-xr-x 2 root root 48 August 22:25 mymusic-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth0-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1- Rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo drwxr-xr-x 2 root root 48 September 6 13:06 VMware can see the conkyrc.sample file belongs to the user group root, the The one is root. Execute the following command to transfer ownership of the Conkyrc.sample file to the user: [[email protected] ~]# chown user conkyrc.sample [[email protected] ~]# ls-l Total dosage 368-rwxrwxrwx 1 user root 12172 August 23:18 conkyrc.sample drwxr-xr-x 2 root root 48 September 4 16:32 desktop-r- -r--r--1 root root 331844 October 21:08 libfreetype.so.6 drwxr-xr-x 2 root root 48 August 22:25 Mymusic-rwxr-xr-x 1 root R Oot 9776 November 5 08:08 net.eth0-rwxr-xr-x 1 root root 9776 November 5 08:08 NET.ETh1-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo drwxr-xr-x 2 root root 48 September 6 13:06 VMware to change the owning group, use the following command: [[email  ;p rotected] ~]# chown:users conkyrc.sample [[email protected] ~]# ls-l Total usage 368-rwxrwxrwx 1 user users 12172 August 15 23:18 conkyrc.sample drwxr-xr-x 2 root root 48 September 4 16:32 desktop-r--r--r--1 root root 331844 October 21:08 libfreetype.s O.6 drwxr-xr-x 2 root root 48 August 22:25 mymusic-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth0-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo drwxr-xr-x 2 root root 48 September 6 13:06 VMware to modify the directory permissions, use the-R parameter, and the method is the same as before
How to view and modify file read and write permissions under the Linux notes _linux system