Linux management authority and ownership of the file / directory detailing

First, the file permissions and ownership Overview

1. Access

  • Read r: allows you to view the contents of a file, directory listing;

  • Write w: allows you to modify the contents of the file, allowing the new directory, move, delete files or subdirectories;

  • Executable x: allowed to run the program, change directory

2, ownership (ownership)

  • Owner: the user who owns the file or directory account;

  • Is a group: the group that owns the account file or directory;

3, view file permissions and ownership

Linux management authority and ownership of the file / directory succinctly

4, chmod to set file permissions

The basic syntax chmod command is as follows:
Linux management authority and ownership of the file / directory succinctly

Application examples:

[root@01 ~]# touch 1.txt     <!--创建1.txt文件-->
[root@centos01 ~]# ll 
总用量 8
-rw-r--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u+x ./1.txt  <!--属主用户添加执行权限-->
[root@centos01 ~]# ll
总用量 8
-rwxr--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u-x,g+x,o+w 1.txt   
<!--属主用户取消执行权限,组添加执行权限,其他用户添加写入权限-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod 755 1.txt  <!--添加755权限(rwxr-xr-x)-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 root root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

5, setting file ownership chown

The basic syntax chown command is as follows:
Linux management authority and ownership of the file / directory succinctly

Application examples:

[root@centos01 ~]# chown bob 1.txt  <!--1.txt设置属主-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown :benet 1.txt  <!--1.txt设置属组-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown bob:benet 1.txt  <!--1.txt设置属主和属组-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
<!---->

Second, the directory permissions and ownership

1. Access

Linux management authority and ownership of the file / directory succinctly

2, ownership (ownership)

  • Owner: the user who owns the account directory;

  • Is a group: the group that owns the account directory;

3, chmod to set directory permissions

chmod command to set the directory permissions basic format is as follows:
Linux management authority and ownership of the file / directory succinctly

Application examples:

[root@centos01 ~]# chmod -R 755 benet/   
          <!--循环设置benet目录下的文件或者目录权限为755-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 root root   18 1月  11 22:39 benet
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

4, chown Set the Home directory

chown command to set the home directory of the basic format is as follows:
Linux management authority and ownership of the file / directory succinctly

Application examples:

[root@centos01 ~]# chown -R bob:benet benet/   
   <!--循环设置benet目录中所属用户为bob,所属组为benet-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw-  1 root root     0 1月  11 22:27 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 bob  benet   18 1月  11 22:39 benet
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

Third, the permission mask umask

1, umask action

The new control permissions on the file or directory permissions umask permission to remove the default permissions that the new file or directory.

2, set the umask

umask 022

3, see umask

umask

4. Application examples:

[root@centos01 ~]# umask  <!--查看umask-->
0022
[root@centos01 ~]# umask 000  <!--设置umask为000-->
[root@centos01 ~]# umask   <!--验证是否设置成功-->
0000
[root@centos01 ~]# touch 2.txt   <!--创建新文件-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt    <!--查看权限-->
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# umask 022       <!--设置umask为022-->
[root@centos01 ~]# umask           <!--查看umask-->
0022
[root@centos01 ~]# touch 3.txt        <!--再次创建新文件-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt
-rw-r--r--  1 root root     0 1月  17 03:49 3.txt <!--查看权限,明显不一样-->
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

Guess you like

Origin www.linuxidc.com/Linux/2020-01/162121.htm