Owner permissions and group permissions

Linux file attributes

Linux system is a typical multi-user systems, different users have different status, with different privileges. To protect the security of the system, Linux system access the same file (including directory files) for different users to do different provisions.

Users and groups can be used in Linux we ll or ls -l command to display the attributes of a file and the file belongs

E.g:

Copy the code
[root @ bogon /] # ls -l 
total volume of 24 
lrwxrwxrwx the root. 1. 6. 7 dated the root bin 21:30. 6 -.> usr / bin 
. DR XR-XR-4096-X. 5 the root the root. 6 dated 16 11:29 boot 
drwxr-xr-x. 20 root root 3300 11:51 dev. 6 dated 16 
drwxr-XR-X. 8192 146 the root the root. 6 12:10 etc dated 16 
drwxr-XR-X.. 4 the root the root 36 at 11:45 on June 8 Home 
lrwxrwxrwx the root. 1. 6. 7 dated the root lib 21:30. 6 -.> usr / lib 
lrwxrwxrwx the root the root. 1. 6. 9 dated the lib64 21:30. 6 -.> usr / the lib64 
. drwxr the root-XR-2 X the root. 6 April 11 Media 2018 
drwxr-XR-X. 2. 6. 4 the root the root dated 2018 mnt. 11 
drwxr-XR-X.. 4 30. 6 dated the root the root opt 15:20. 6 
DR-X-XR-XR. the root 290 is the root. 6 dated 16 11 0 : 51 is proc 
DR-XR X-219. 6 --- the root the root. 6 dated 16 11:27 root. 
drwxr X-40 XR-1240 is the root the root. 6 dated 16 12:10 run.
lrwxrwxrwx.   1 root root    8 6月   6 21:30 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 6月  16 11:51 sys
drwxrwxrwt.  30 root root 4096 6月  16 12:38 tmp
drwxr-xr-x.  13 root root  155 6月   6 21:30 usr
drwxr-xr-x.  21 root root 4096 6月   6 21:54 var
Copy the code

In Linux the first character represents the file is a directory, the file or linked files, and so on.

  • As for the [  D] is a directory
  • As for the [  -] is a file;
  • If [  L] is represented as a linked document (link file);
  • If the [  B] indicates that the interface device is a device for storage of the files inside (random access device);
  • If the [  C] indicates the serial port device is a file inside the device, such as a keyboard, a mouse (one reading device).

The next character to three as a group, and are a combination of three parameters of "rwx" of. Wherein, on behalf of [r] read (read), [w] Representative writable (write), [x] Representative executable (execute). It should be noted that the location of these three privileges do not change, if there is no authority, there will be a minus sign [-]

Owner user / group metal group / others others

Attribute of each file is determined by the character of the first portion 10 to the left

From left to right are represented by the numbers 0-9.

Bit 0 determine file types, positions 1-3 to determine the owner (owner of the file) have access to the file.

The first set 4-6 to determine the genus (group of users with the owners) have access to the file, 7-9 bits identify other users who have access to the file.

Linux file the owner and group

analysis

[root@bogon /]# ls -l
total 64
drwxr-xr-x 2 root  root  4096 Feb 15 14:46 cron
drwxr-xr-x 3 mysql mysql 4096 Apr 21  2014 mysql
……

For files, it has a particular owner, that is, the user has the file ownership.

Meanwhile, in the Linux system, users are classified into groups of one or more users belonging to one group.

Users outside of the owner of the file can be divided into the same group of users of the file owner and other users.

Therefore, Linux system by file owner, file owner with the group and other users to specify a different file access rights.

In the above example, mysql file is a directory file, the owner and group are mysql, owner have read, write, execute permissions; other users of the same group owner has readable and executable by permissions; other users have permission readable and executable.

For root users, under normal circumstances, it does not work the file permissions.

Change the file attributes

1, chgrp: Change the file owner group

chgrp [-R] filename is a group

Parameters -R: recursively change the file belongs to the group, that is, when you change a file's directory belong to the group, if coupled with -R parameter, then the group will change belongs to all the files in that directory.

2, chown: Change file owner, you can also change the file belongs to the group at the same time

grammar:

chown [-R] owner name of the file name 
chown [-R] owner name: name of the file name is a group

test

Enter the / root directory (~) to see what files in the current directory

Copy the code

[root@bogon /]# cd ~
[root@bogon ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg

[root @ bogon ~] # ls -l
total volume. 8
-rw ------- 1755. 6. 1 the root the root-dated the ks.cfg Anaconda 21:43. 6.
-rw-R & lt -.. 1 the root r-- root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

Copy the code

The anaconda-ks.cfg modified owner

[bogon the root @ ~] # chown bin-Anaconda the ks.cfg 
[bogon the root @ ~] -l # LS 
total volume. 8 
-rw -------.. 1 1755 the root bin. 6 dated 6 21:43 anaconda-ks .cfg 
-rw-r -. r-- 1 root root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

The anaconda-ks.cfg owner and group changed back to root:

[bogon the root @ ~] # chown the root: the root-Anaconda the ks.cfg
[bogon the root @ ~] -l # LS
total volume. 8
-rw -------. 1 1755 the root the root. 6 dated 6 21:43 anaconda. -ks.cfg
-rw-r -. r-- 1 root root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

3, chmod: change file attributes 9

Linux file attributes There are two settings, one is a symbol, one is digital.

Basic Linux file permissions have nine, respectively, is owner / group / others Three Identities have their own read / write / execute permissions.

To review the data just mentioned above: file permissions characters: "- rwxrwxrwx" nine permissions are three groups of three! Among them, we can use the number to represent each permission, the score table for each of the following rights:

  • r:4
  • w:2
  • x:1

Each identity (owner / group / others) of each of three permission (r / w / x) cumulative score is needed, for example, when permission is: [-rwxrwx ---] score is:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= --- = 0+0+0 = 0

When we set change permissions, digital rights of the file is 770

Chmod command syntax permission to change is this:

 chmod [-R] xyz file or directory

Options and parameters:

  • xyz: is the digital rights attribute type just mentioned, the attribute value is added to rwx.
  • -R: recursive (recursive) continues to change, that is, together with all files in subdirectories change

For example, if you want all the permissions are set to enable .bashrc file, then the command is as follows:

[root@bogon ~]# ls -al .bashrc
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
[root@bogon ~]# chmod 777 .bashrc
[root@bogon ~]# ls -al .bashrc
-rwxrwxrwx. 1 root root 176 12月 29 2013 .bashrc

Also just return the file permissions only need to calculate the sum of the initial permissions

[root@bogon ~]# chmod 644 .bashrc
[root@bogon ~]# ls -al .bashrc
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc

This is like the very beginning as a query permissions

Symbol Type change file permissions

There is also a way to change the permissions from the previous description, we can find, essentially nine privileges are:

  • (1)user
  • (2)group
  • (3)others

Then we can use the  u, g, o  to represent the rights of the Three Identities!

In addition,  A  represents the  All , that is, all identity. Performing read and write permissions can be written as  r, w, x

You can use + - = to modify permissions:

For example, we need to set file permissions  -rwxr-XR,  , may be used  chmod u = rwx, g = rx , o = r to set a file name:

We create a file to test next

[root @ bogon ~] # touch test1 // Create a test file 
[root @ bogon ~] # test1 LS -al 
-rw-r -. r-- 1 root root 0 6 Yue 16 14:08 test1

Modify permissions:

[root@bogon ~]# chmod u=rwx,g=rx,o=r test1
[root@bogon ~]# ls -al test1
-rwxr-xr--. 1 root root 0 6月  16 14:08 test1

If you want to remove permissions without changing other rights already exist it? For example, to remove all of the people of executable permissions, then:

[root@bogon ~]# chmod a-x test1
[root@bogon ~]# ls -al test1
-rw-r--r--. 1 root root 0 6月  16 14:08 test1

 

Linux system is a typical multi-user systems, different users have different status, with different privileges. To protect the security of the system, Linux system access the same file (including directory files) for different users to do different provisions.

Users and groups can be used in Linux we ll or ls -l command to display the attributes of a file and the file belongs

E.g:

Copy the code
[root @ bogon /] # ls -l 
total volume of 24 
lrwxrwxrwx the root. 1. 6. 7 dated the root bin 21:30. 6 -.> usr / bin 
. DR XR-XR-4096-X. 5 the root the root. 6 dated 16 11:29 boot 
drwxr-xr-x. 20 root root 3300 11:51 dev. 6 dated 16 
drwxr-XR-X. 8192 146 the root the root. 6 12:10 etc dated 16 
drwxr-XR-X.. 4 the root the root 36 at 11:45 on June 8 Home 
lrwxrwxrwx the root. 1. 6. 7 dated the root lib 21:30. 6 -.> usr / lib 
lrwxrwxrwx the root the root. 1. 6. 9 dated the lib64 21:30. 6 -.> usr / the lib64 
. drwxr the root-XR-2 X the root. 6 April 11 Media 2018 
drwxr-XR-X. 2. 6. 4 the root the root dated 2018 mnt. 11 
drwxr-XR-X.. 4 30. 6 dated the root the root opt 15:20. 6 
DR-X-XR-XR. the root 290 is the root. 6 dated 16 11 0 : 51 is proc 
DR-XR X-219. 6 --- the root the root. 6 dated 16 11:27 root. 
drwxr X-40 XR-1240 is the root the root. 6 dated 16 12:10 run.
lrwxrwxrwx.   1 root root    8 6月   6 21:30 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 6月  16 11:51 sys
drwxrwxrwt.  30 root root 4096 6月  16 12:38 tmp
drwxr-xr-x.  13 root root  155 6月   6 21:30 usr
drwxr-xr-x.  21 root root 4096 6月   6 21:54 var
Copy the code

In Linux the first character represents the file is a directory, the file or linked files, and so on.

  • As for the [  D] is a directory
  • As for the [  -] is a file;
  • If [  L] is represented as a linked document (link file);
  • If the [  B] indicates that the interface device is a device for storage of the files inside (random access device);
  • If the [  C] indicates the serial port device is a file inside the device, such as a keyboard, a mouse (one reading device).

The next character to three as a group, and are a combination of three parameters of "rwx" of. Wherein, on behalf of [r] read (read), [w] Representative writable (write), [x] Representative executable (execute). It should be noted that the location of these three privileges do not change, if there is no authority, there will be a minus sign [-]

Owner user / group metal group / others others

Attribute of each file is determined by the character of the first portion 10 to the left

From left to right are represented by the numbers 0-9.

Bit 0 determine file types, positions 1-3 to determine the owner (owner of the file) have access to the file.

The first set 4-6 to determine the genus (group of users with the owners) have access to the file, 7-9 bits identify other users who have access to the file.

Linux file the owner and group

analysis

[root@bogon /]# ls -l
total 64
drwxr-xr-x 2 root  root  4096 Feb 15 14:46 cron
drwxr-xr-x 3 mysql mysql 4096 Apr 21  2014 mysql
……

For files, it has a particular owner, that is, the user has the file ownership.

Meanwhile, in the Linux system, users are classified into groups of one or more users belonging to one group.

Users outside of the owner of the file can be divided into the same group of users of the file owner and other users.

Therefore, Linux system by file owner, file owner with the group and other users to specify a different file access rights.

In the above example, mysql file is a directory file, the owner and group are mysql, owner have read, write, execute permissions; other users of the same group owner has readable and executable by permissions; other users have permission readable and executable.

For root users, under normal circumstances, it does not work the file permissions.

Change the file attributes

1, chgrp: Change the file owner group

chgrp [-R] filename is a group

Parameters -R: recursively change the file belongs to the group, that is, when you change a file's directory belong to the group, if coupled with -R parameter, then the group will change belongs to all the files in that directory.

2, chown: Change file owner, you can also change the file belongs to the group at the same time

grammar:

chown [-R] owner name of the file name 
chown [-R] owner name: name of the file name is a group

test

Enter the / root directory (~) to see what files in the current directory

Copy the code

[root@bogon /]# cd ~
[root@bogon ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg

[root @ bogon ~] # ls -l
total volume. 8
-rw ------- 1755. 6. 1 the root the root-dated the ks.cfg Anaconda 21:43. 6.
-rw-R & lt -.. 1 the root r-- root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

Copy the code

The anaconda-ks.cfg modified owner

[bogon the root @ ~] # chown bin-Anaconda the ks.cfg 
[bogon the root @ ~] -l # LS 
total volume. 8 
-rw -------.. 1 1755 the root bin. 6 dated 6 21:43 anaconda-ks .cfg 
-rw-r -. r-- 1 root root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

The anaconda-ks.cfg owner and group changed back to root:

[bogon the root @ ~] # chown the root: the root-Anaconda the ks.cfg
[bogon the root @ ~] -l # LS
total volume. 8
-rw -------. 1 1755 the root the root. 6 dated 6 21:43 anaconda. -ks.cfg
-rw-r -. r-- 1 root root 1783 6 Yue 6 14:02 initial-setup-ks.cfg

3, chmod: change file attributes 9

Linux file attributes There are two settings, one is a symbol, one is digital.

Basic Linux file permissions have nine, respectively, is owner / group / others Three Identities have their own read / write / execute permissions.

To review the data just mentioned above: file permissions characters: "- rwxrwxrwx" nine permissions are three groups of three! Among them, we can use the number to represent each permission, the score table for each of the following rights:

  • r:4
  • w:2
  • x:1

Each identity (owner / group / others) of each of three permission (r / w / x) cumulative score is needed, for example, when permission is: [-rwxrwx ---] score is:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= --- = 0+0+0 = 0

When we set change permissions, digital rights of the file is 770

Chmod command syntax permission to change is this:

 chmod [-R] xyz file or directory

Options and parameters:

  • xyz: is the digital rights attribute type just mentioned, the attribute value is added to rwx.
  • -R: recursive (recursive) continues to change, that is, together with all files in subdirectories change

For example, if you want all the permissions are set to enable .bashrc file, then the command is as follows:

[root@bogon ~]# ls -al .bashrc
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
[root@bogon ~]# chmod 777 .bashrc
[root@bogon ~]# ls -al .bashrc
-rwxrwxrwx. 1 root root 176 12月 29 2013 .bashrc

Also just return the file permissions only need to calculate the sum of the initial permissions

[root@bogon ~]# chmod 644 .bashrc
[root@bogon ~]# ls -al .bashrc
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc

This is like the very beginning as a query permissions

Symbol Type change file permissions

There is also a way to change the permissions from the previous description, we can find, essentially nine privileges are:

  • (1)user
  • (2)group
  • (3)others

Then we can use the  u, g, o  to represent the rights of the Three Identities!

In addition,  A  represents the  All , that is, all identity. Performing read and write permissions can be written as  r, w, x

You can use + - = to modify permissions:

For example, we need to set file permissions  -rwxr-XR,  , may be used  chmod u = rwx, g = rx , o = r to set a file name:

We create a file to test next

[root @ bogon ~] # touch test1 // Create a test file 
[root @ bogon ~] # test1 LS -al 
-rw-r -. r-- 1 root root 0 6 Yue 16 14:08 test1

Modify permissions:

[root@bogon ~]# chmod u=rwx,g=rx,o=r test1
[root@bogon ~]# ls -al test1
-rwxr-xr--. 1 root root 0 6月  16 14:08 test1

If you want to remove permissions without changing other rights already exist it? For example, to remove all of the people of executable permissions, then:

[root@bogon ~]# chmod a-x test1
[root@bogon ~]# ls -al test1
-rw-r--r--. 1 root root 0 6月  16 14:08 test1

 

Guess you like

Origin www.cnblogs.com/zqzhen/p/12636920.html