[root@k8s-node03 ~]# ll
total 9040
-rw-------. 1 root root    1259 Aug 11 18:24 anaconda-ks.cfg
-rw-r--r--. 1 root root    3619 Aug 15 08:24 index.html
-rw-r--r--. 1 root root 9246179 Aug 24 20:16 node_exporter-1.1.2.linux-amd64.tar.gz
-rw-------
第一个字段是描述文件或者目录权限的码
- :代表文件
drwxr-xr-x  12 root root     4096 Sep 12 09:00 data
d :d代表目录
lrwxrwxrwx  1 root root    11 Aug 24 22:10 ifdown-isdn -> ifdown-ippp
l: l代表链接
r 八进制值是4
w 八进制值是2
x 八进制值是1
所以 rw 6
rx 5
wx 3
rwx 7


创建共享文件

[root@k8s-node02 ~]# mkdir /shared    #创建一个共享文件目录shared
[root@k8s-node02 ~]# cd /shared
[root@k8s-node02 shared]# ll
total 0
[root@k8s-node02 shared]# cd /
[root@k8s-node02 /]# ll
total 16
drwxr-xr-x.   2 root root   39 Aug 23 08:34 app
lrwxrwxrwx.   1 root root    7 Aug 11 18:10 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Aug 31 10:55 boot
drwxr-xr-x.   3 root root   26 Aug 23 08:44 build
drwxr-xr-x.   2 root root    6 Aug 24 23:49 data
drwxr-xr-x.  19 root root 3140 Aug 11 18:19 dev
drwxr-xr-x.  88 root root 8192 Aug 31 12:36 etc
drwxr-xr-x.   3 root root   20 Aug 31 09:12 home
lrwxrwxrwx.   1 root root    7 Aug 11 18:10 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Aug 11 18:10 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Apr 11  2018 media
drwxr-xr-x.   2 root root    6 Apr 11  2018 mnt
drwxr-xr-x.   3 root root   18 Sep  1 21:02 mysql
drwxr-xr-x.   4 root root   35 Aug 11 18:38 opt
dr-xr-xr-x. 287 root root    0 Aug 11 18:19 proc
dr-xr-x---.   5 root root  252 Aug 28 21:58 root
drwxr-xr-x.  31 root root 1020 Aug 31 12:37 run
lrwxrwxrwx.   1 root root    8 Aug 11 18:10 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Sep 12 13:59 shared             #创建时候目录权限情况
drwxr-xr-x.   2 root root    6 Apr 11  2018 srv
dr-xr-xr-x.  13 root root    0 Aug 11 18:19 sys
drwxrwxrwt.   9 root root  263 Sep 12 13:57 tmp
drwxr-xr-x.  13 root root  155 Aug 11 18:10 usr
drwxr-xr-x.  19 root root  267 Aug 11 18:19 var
[root@k8s-node02 /]# groupadd shared                #创建一个共享组shared
[root@k8s-node02 /]# chgrp shared shared             #通过chgrp命令将目录的默认属组改为含有所有需要共享文件用户的组。
[root@k8s-node02 /]# chmod 775 shared                #给与shared目录755权限
[root@k8s-node02 /]# ll
total 16
drwxr-xr-x.   2 root root     39 Aug 23 08:34 app
lrwxrwxrwx.   1 root root      7 Aug 11 18:10 bin -> usr/bin
dr-xr-xr-x.   5 root root   4096 Aug 31 10:55 boot
drwxr-xr-x.   3 root root     26 Aug 23 08:44 build
drwxr-xr-x.   2 root root      6 Aug 24 23:49 data
drwxr-xr-x.  19 root root   3140 Aug 11 18:19 dev
drwxr-xr-x.  88 root root   8192 Sep 12 14:00 etc
drwxr-xr-x.   3 root root     20 Aug 31 09:12 home
lrwxrwxrwx.   1 root root      7 Aug 11 18:10 lib -> usr/lib
lrwxrwxrwx.   1 root root      9 Aug 11 18:10 lib64 -> usr/lib64
drwxr-xr-x.   2 root root      6 Apr 11  2018 media
drwxr-xr-x.   2 root root      6 Apr 11  2018 mnt
drwxr-xr-x.   3 root root     18 Sep  1 21:02 mysql
drwxr-xr-x.   4 root root     35 Aug 11 18:38 opt
dr-xr-xr-x. 287 root root      0 Aug 11 18:19 proc
dr-xr-x---.   5 root root    252 Aug 28 21:58 root
drwxr-xr-x.  31 root root   1020 Aug 31 12:37 run
lrwxrwxrwx.   1 root root      8 Aug 11 18:10 sbin -> usr/sbin
drwxrwxr-x.   2 root shared    6 Sep 12 13:59 shared         #看到属组已经是shared了
drwxr-xr-x.   2 root root      6 Apr 11  2018 srv
dr-xr-xr-x.  13 root root      0 Aug 11 18:19 sys
drwxrwxrwt.   9 root root    263 Sep 12 13:57 tmp
drwxr-xr-x.  13 root root    155 Aug 11 18:10 usr
drwxr-xr-x.  19 root root    267 Aug 11 18:19 var
[root@k8s-node02 /]# chmod g+s shared                        #该命令会使目录中创建的新文件以目录默认属组作为默认属组
[root@k8s-node02 /]# ll
total 16
drwxr-xr-x.   2 root root     39 Aug 23 08:34 app
lrwxrwxrwx.   1 root root      7 Aug 11 18:10 bin -> usr/bin
dr-xr-xr-x.   5 root root   4096 Aug 31 10:55 boot
drwxr-xr-x.   3 root root     26 Aug 23 08:44 build
drwxr-xr-x.   2 root root      6 Aug 24 23:49 data
drwxr-xr-x.  19 root root   3140 Aug 11 18:19 dev
drwxr-xr-x.  88 root root   8192 Sep 12 14:00 etc
drwxr-xr-x.   3 root root     20 Aug 31 09:12 home
lrwxrwxrwx.   1 root root      7 Aug 11 18:10 lib -> usr/lib
lrwxrwxrwx.   1 root root      9 Aug 11 18:10 lib64 -> usr/lib64
drwxr-xr-x.   2 root root      6 Apr 11  2018 media
drwxr-xr-x.   2 root root      6 Apr 11  2018 mnt
drwxr-xr-x.   3 root root     18 Sep  1 21:02 mysql
drwxr-xr-x.   4 root root     35 Aug 11 18:38 opt
dr-xr-xr-x. 287 root root      0 Aug 11 18:19 proc
dr-xr-x---.   5 root root    252 Aug 28 21:58 root
drwxr-xr-x.  31 root root   1020 Aug 31 12:37 run
lrwxrwxrwx.   1 root root      8 Aug 11 18:10 sbin -> usr/sbin
drwxrwsr-x.   2 root shared    6 Sep 12 13:59 shared       #可以看到权限里有个s
drwxr-xr-x.   2 root root      6 Apr 11  2018 srv
dr-xr-xr-x.  13 root root      0 Aug 11 18:19 sys
drwxrwxrwt.   9 root root    263 Sep 12 13:57 tmp
drwxr-xr-x.  13 root root    155 Aug 11 18:10 usr
drwxr-xr-x.  19 root root    267 Aug 11 18:19 var
[root@k8s-node02 /]# umask 002        该命令使目录下文件是对属组可写
[root@k8s-node02 /]# cd shared
[root@k8s-node02 shared]# touch a.txt    #创建一个文件,查看权限
[root@k8s-node02 shared]# ll
total 0
-rw-rw-r--. 1 root shared 0 Sep 12 14:01 a.txt

再创建一个文件

[liutao@k8s-node02 shared]$ ll
total 0
-rw-rw-r--. 1 root shared 0 Sep 12 14:01 a.txt
-rw-r--r--. 1 root shared 0 Sep 12 14:19 b.txt

可以看到属主属组一样

普通用户记得命令前面带上sudo