[TOC]html
drwxr-xr-x. 4 root root 31 Oct 4 00:54 zhanghao
drwxr-xr-x:node
第一个字符d: 表示文件类型vim
例题:假设test1, test2, test3同属于testgroup这个群组,若是有下面的两个文件,请说明两个 文件的拥有者与其相关的权限为什么? -rw-r--r-- 1 root root 238 Jun 18 17:22 test.txt -rwxr-xr-- 1 test1 testgroup 5238 Jun 19 10:25 ping_tsai
答:安全
在本目录下进行写入的动做;bash
* 至于other的权限中[r--]虽然有r ,可是因为没有x的权限,所以others的使用者,并不能进
入此目录!spa
[zhanghao@zhanghao-server ~]$ cd /home/test1/ -bash: cd: /home/test1/: Permission denied [zhanghao@zhanghao-server ~]$ ls [zhanghao@zhanghao-server ~]$ exit logout [root@zhanghao-server test1]# su - test2 [test2@zhanghao-server ~]$ cd /home/test1/ -bash: cd: /home/test1/: Permission denied [test2@zhanghao-server ~]$ ll /home/test1/ ls: cannot open directory /home/test1/: Permission denied [test2@zhanghao-server ~]$ exit logout [root@zhanghao-server test1]# ll /home/ total 0 drwx------. 3 test1 test 95 Oct 4 03:54 test1 drwx------. 2 test2 test 83 Oct 4 03:55 test2 drwx------. 2 zhanghao zhanghao 83 Oct 4 03:55 zhanghao
从上面看,test1和test2虽然是属于同一个test组,可是/home下面目录对于组没有任何的权限,给组一个读权限
[root@zhanghao-server test1]# chmod 0611 /home/test1 [root@zhanghao-server test1]# su - test2 Last login: Thu Oct 4 03:55:27 EDT 2018 on pts/0 [test2@zhanghao-server ~]$ cd /home/test1/ [test2@zhanghao-server test1]$ ls ls: cannot open directory .: Permission denied
从上面能够看出其余用户在test1目录下面没有任何的读写,没办法ls,touch。cd属于执行权限
[root@zhanghao-server home]# chmod 755 test1 [root@zhanghao-server home]# ll -h total 0 drwxr-xr-x. 3 test1 test 95 Oct 4 03:54 test1 drwx------. 2 test2 test 83 Oct 4 03:55 test2 drwx------. 2 zhanghao zhanghao 83 Oct 4 03:55 zhanghao [root@zhanghao-server home]# su - test2 Last login: Thu Oct 4 03:58:41 EDT 2018 on pts/0 [test2@zhanghao-server ~]$ cd /home/test1 [test2@zhanghao-server test1]$ ls test [test2@zhanghao-server test1]$ touch nihao touch: cannot touch ‘nihao’: Permission denied [test2@zhanghao-server test1]$ cd test/ [test2@zhanghao-server test]$ ls nihao [test2@zhanghao-server test]$ cat nihao o test1 cat: o: No such file or directory [test2@zhanghao-server test]$ cat nihao test1 [test2@zhanghao-server test]$ vim nihao -bash: vim: command not found [test2@zhanghao-server test]$ vi nihao
vim 保存显示只读文件。没法touch,
/zhanghao目录其余人权限为0,新建用户zhtest在zhanghao组中,能够有执行和读的权限,不能写。
[zhanghao@zhanghao-server home]$ touch zhanghao [zhanghao@zhanghao-server home]$ exit logout [root@zhanghao-server ~]# su - test1 Last login: Thu Oct 4 03:53:52 EDT 2018 on pts/0 [test1@zhanghao-server ~]$ cd /home/ [test1@zhanghao-server home]$ ls nihao test1 test2 zhanghao [root@zhanghao-server /]# chmod 0750 /zhanghao/ [root@zhanghao-server /]# ll / total 24 lrwxrwxrwx. 1 root root 7 Oct 3 00:14 bin -> usr/bin dr-xr-xr-x. 4 root root 4096 Oct 3 04:00 boot drwxr-xr-x. 19 root root 3160 Oct 4 02:29 dev drwxr-xr-x. 80 root root 8192 Oct 4 03:55 etc drwxr-xr-x. 5 root root 61 Oct 4 04:09 home lrwxrwxrwx. 1 root root 7 Oct 3 00:14 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Oct 3 00:14 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 Mar 10 2016 media dr-xr-xr-x. 9 root root 4096 Jul 11 2017 mnt drwxr-xr-x. 2 root root 6 Mar 10 2016 opt dr-xr-xr-x. 106 root root 0 Oct 3 23:55 proc dr-xr-x---. 3 root root 147 Oct 4 00:17 root drwxr-xr-x. 26 root root 800 Oct 4 00:20 run lrwxrwxrwx. 1 root root 8 Oct 3 00:14 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 Mar 10 2016 srv dr-xr-xr-x. 13 root root 0 Oct 3 23:55 sys drwxrwxrwt. 11 root root 4096 Oct 4 03:26 tmp drwxr-xr-x. 13 root root 155 Oct 3 00:14 usr drwxr-xr-x. 19 root root 267 Oct 3 03:55 var drwxr-x---. 4 zhanghao zhanghao 31 Oct 4 00:54 zhanghao [root@zhanghao-server /]# su - test1 Last login: Thu Oct 4 04:18:33 EDT 2018 on pts/0 [test1@zhanghao-server ~]$ ls test [test1@zhanghao-server ~]$ cd /zhanghao/ -bash: cd: /zhanghao/: Permission denied [test1@zhanghao-server ~]$ [root@zhanghao-server /]# useradd zhtest -g zhanghao [root@zhanghao-server /]# su - zhtest [zhtest@zhanghao-server ~]$ cd /zhanghao/ [zhtest@zhanghao-server zhanghao]$ ls test test1 [zhtest@zhanghao-server zhanghao]$ touch niaho touch: cannot touch ‘niaho’: Permission denied
将/zhanghao目录的组权限修改成test,让test组下面的用户test1,有读和执行的权限。
[root@zhanghao-server /]# chgrp test /zhanghao [root@zhanghao-server /]# ll -h total 24K lrwxrwxrwx. 1 root root 7 Oct 3 00:14 bin -> usr/bin dr-xr-xr-x. 4 root root 4.0K Oct 3 04:00 boot drwxr-xr-x. 19 root root 3.1K Oct 4 02:29 dev drwxr-xr-x. 80 root root 8.0K Oct 4 04:21 etc drwxr-xr-x. 6 root root 75 Oct 4 04:21 home lrwxrwxrwx. 1 root root 7 Oct 3 00:14 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Oct 3 00:14 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 Mar 10 2016 media dr-xr-xr-x. 9 root root 4.0K Jul 11 2017 mnt drwxr-xr-x. 2 root root 6 Mar 10 2016 opt dr-xr-xr-x. 106 root root 0 Oct 3 23:55 proc dr-xr-x---. 3 root root 147 Oct 4 00:17 root drwxr-xr-x. 26 root root 800 Oct 4 00:20 run lrwxrwxrwx. 1 root root 8 Oct 3 00:14 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 Mar 10 2016 srv dr-xr-xr-x. 13 root root 0 Oct 3 23:55 sys drwxrwxrwt. 11 root root 4.0K Oct 4 03:26 tmp drwxr-xr-x. 13 root root 155 Oct 3 00:14 usr drwxr-xr-x. 19 root root 267 Oct 3 03:55 var drwxr-x---. 4 zhanghao test 31 Oct 4 00:54 zhanghao [root@zhanghao-server /]# su - test1 Last login: Thu Oct 4 04:19:58 EDT 2018 on pts/0 [test1@zhanghao-server ~]$ cd /zhanghao/ [test1@zhanghao-server zhanghao]$ ls test test1 [test1@zhanghao-server zhanghao]$ touch nihao touch: cannot touch ‘nihao’: Permission denied
修改文件拥有者
[root@zhanghao-server /]# chown -R root:root /zhanghao [root@zhanghao-server /]# ll / total 24 lrwxrwxrwx. 1 root root 7 Oct 3 00:14 bin -> usr/bin dr-xr-xr-x. 4 root root 4096 Oct 3 04:00 boot drwxr-xr-x. 19 root root 3160 Oct 4 02:29 dev drwxr-xr-x. 80 root root 8192 Oct 4 04:21 etc drwxr-xr-x. 6 root root 75 Oct 4 04:21 home lrwxrwxrwx. 1 root root 7 Oct 3 00:14 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Oct 3 00:14 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 Mar 10 2016 media dr-xr-xr-x. 9 root root 4096 Jul 11 2017 mnt drwxr-xr-x. 2 root root 6 Mar 10 2016 opt dr-xr-xr-x. 107 root root 0 Oct 3 23:55 proc dr-xr-x---. 3 root root 147 Oct 4 00:17 root drwxr-xr-x. 26 root root 800 Oct 4 00:20 run lrwxrwxrwx. 1 root root 8 Oct 3 00:14 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 Mar 10 2016 srv dr-xr-xr-x. 13 root root 0 Oct 3 23:55 sys drwxrwxrwt. 11 root root 4096 Oct 4 03:26 tmp drwxr-xr-x. 13 root root 155 Oct 3 00:14 usr drwxr-xr-x. 19 root root 267 Oct 3 03:55 var drwxr-x---. 4 root root 31 Oct 4 00:54 zhanghao
chown -R 用户: 组 文件, 能够单纯的改组
[root@zhanghao-server /]# chown -R :test zhanghao [root@zhanghao-server /]# ll -h total 24K lrwxrwxrwx. 1 root root 7 Oct 3 00:14 bin -> usr/bin dr-xr-xr-x. 4 root root 4.0K Oct 3 04:00 boot drwxr-xr-x. 19 root root 3.1K Oct 4 02:29 dev drwxr-xr-x. 80 root root 8.0K Oct 4 04:21 etc drwxr-xr-x. 6 root root 75 Oct 4 04:21 home lrwxrwxrwx. 1 root root 7 Oct 3 00:14 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Oct 3 00:14 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 Mar 10 2016 media dr-xr-xr-x. 9 root root 4.0K Jul 11 2017 mnt drwxr-xr-x. 2 root root 6 Mar 10 2016 opt dr-xr-xr-x. 107 root root 0 Oct 3 23:55 proc dr-xr-x---. 3 root root 147 Oct 4 00:17 root drwxr-xr-x. 26 root root 800 Oct 4 00:20 run lrwxrwxrwx. 1 root root 8 Oct 3 00:14 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 Mar 10 2016 srv dr-xr-xr-x. 13 root root 0 Oct 3 23:55 sys drwxrwxrwt. 11 root root 4.0K Oct 4 03:26 tmp drwxr-xr-x. 13 root root 155 Oct 3 00:14 usr drwxr-xr-x. 19 root root 267 Oct 3 03:55 var drwxr-x---. 4 root test 31 Oct 4 00:54 zhanghao
权限code
附加者server
chmod 755 filename
chmod u=rwx,go=rx filename
显示当前用户建立目录和文件夹的时候,默认的权限,用777减去umask值是默认的权限值
,umask后面加上数字表示设置。htm
[root@zhanghao-server ~]# umask 0022 [root@zhanghao-server ~]# umask -S u=rwx,g=rx,o=rx
[root@study ~]# chattr [+-=][ASacdistu] 文件或目录名称 选项与参数: + :增长某一个特殊参数,其余本来存在参数则不动。 - :移除某一个特殊参数,其余本来存在参数则不动。 = :设置必定,且仅有后面接的参数 A :当设置了 A 这个属性时,若你有存取此文件(或目录) 时,他的存取时间 atime 将不会被修改,可避免 I/O 较慢的机器过分的存取磁盘。(目前建议使用文件系统挂载参数处理这个项目) S :通常文件是非同步写入磁盘的(原理请参考[前一章sync](../Text/index.html#sync)的说明) ,若是加上 S 这个属性时,当你进行任何文件的修改,该更动会“同步”写入磁盘中。 a :当设置 a 以后,这个文件将只能增长数据,而不能删除也不能修改数据,只有root 才能设置这属性 c :这个属性设置以后,将会自动的将此文件“压缩”,在读取的时候将会自动解压缩,可是在储存的时候,将会先进行压缩后再储存(看来对于大文件彷佛蛮有用的!) d :当 dump 程序被执行的时候,设置 d 属性将可以使该文件(或目录) 不会被 dump 备份 i :这个 i 可就很厉害了!他可让一个文件“不能被删除、更名、设置连接也没法写入或新增数据!”对于系统安全性有至关大的助益!只有 root 能设置此属性 s :当文件设置了 s 属性时,若是这个文件被删除,他将会被彻底的移除出这个硬盘空间,因此若是误删了,彻底没法救回来了喔! u :与 s 相反的,当使用 u 来设置文件时,若是该文件被删除了,则数据内容其实还存在磁盘中,可使用来救援该文件喔! 注意1:属性设置常见的是 a 与 i 的设置值,并且不少设置值必需要身为 root 才能设置 注意2:xfs 文件系统仅支持 AadiS 而已 范例:请尝试到/tmp下面建立文件,并加入 i 的参数,尝试删除看看。 [root@study ~]# cd /tmp [root@study tmp]# touch attrtest <==建立一个空文件 [root@study tmp]# chattr +i attrtest <==给予 i 的属性 [root@study tmp]# rm attrtest <==尝试删除看看 rm: remove regular empty file `attrtest'? y rm: cannot remove `attrtest': Operation not permitted # 看到了吗?呼呼!连 root 也没有办法将这个文件删除呢!赶忙解除设置! 范例:请将该文件的 i 属性取消! [root@study tmp]# chattr -i attrtest
SUID只能在二进制执行文件上生效,好比/usr/bin/passwd上面。普通用户执行具备SUID权限的二进制权限的时候,会临时具备root用户的超级权限。也就是说普通用户也是能够执行。ip
SGID对于目录和文件也有效, 程序执行须要用户有执行x权限。假如我用zhanghao用户执行,zhanghao用户的组是zhanghao,可是我要执行文件的用户组是haozi,那么我用zhanghao执行就会有haozi组的权限,对于目录和文件来讲,有SGID权限,使用者能够对这个目录进行读和执行。
只是对于目录有效,对于文件已经没有任何效果。
好比/tmp目录。拥有SBIT目录,在里面建立的文件只有本身或者root权限才能够删除。
### SUID $ chmod 4755 ### SGID $ chmod 2755 ### SBIT $ chmod 1755