Attr理解为属性,attribution

一lsattr

列出隐藏属性信息

参数 :

-d 只列出目录

-R 递归显示隐藏信息,就是所有子目录中的文件得到遍历

-a 包括隐藏文件和.目录..目录

[root@localhost test]# ll -R

.:

total 4

-rw-r--r--. 1 root root 0 Apr 21 07:20 1.txt

drwxr-xr-x. 2 root root 4096 Apr 21 07:23 test2

./test2:

total 0

-rw-r--r--. 1 root root 0 Apr 21 07:23 2.txt

[root@localhost test]# lsattr -R

-------------e- ./test2

./test2:

-------------e- ./test2/2.txt

-------------e- ./1.txt

这里,我们新建一个.test文件,然后lsattr一下

[root@localhost test]# touch .test

[root@localhost test]# lsattr

-------------e- ./test2

-------------e- ./1.txt

默认情况下,我们发现,lsattr只显示目录下的直观的,隐藏的文件,递归的目录均不显示我们用,lsattr a试一下

[root@localhost test]# lsattr -a

--------------- ./..

-------------e- ./test2

-------------e- ./.

-------------e- ./1.txt

-------------e- ./.test#隐藏文件

当我们想显示某个目录的隐藏属性时,如test,可以进入上层目录,输入lsattr d /PATH/TO/DIR

[root@localhost /]# lsattr -d /test

-------------e- /test

二 chattr

①chattr [|+] i /PATH/TO/FILE OR DIR

I理解为自我I,这时候文件始终存在,切不能被删除与添加,想象系统重要文件,

[root@localhost /]# chattr +i /test/

[root@localhost /]# touch haha.txt /test

touch: setting times of `/test': Permission denied

②chattr [-|+]a /PATH/TO/FILE OR DIR

a理解为add增加,这时候,文件只能增加,也不可以被删除,想象日志文件log

[root@localhost /]# lsattr -d /test

-------------e- /test

[root@localhost /]# chattr +a /test/1.txt

[root@localhost /]# lsattr /test/1.txt

-----a-------e- /test/1.txt

[root@localhost /]# echo "hello" >/test/1.txt

-bash: /test/1.txt: Operation not permitted#权限不够,因为设置了add权限

[root@localhost /]# rm /test/1.txt

rm: remove regular empty file `/test/1.txt'? y

rm: cannot remove `/test/1.txt': Operation not permitted#也不能删除,日志当然不能删除咯

三 特殊权限 SUID SGID STICKY

S理解为set,

  1. SetUID(针对二进制文件!)(chmod 4XXX chmod u+s)

    当其他用户执行该二进制文件时暂时拥有其所有者的权限,比如/bin/ls这个文件

  2. SetGID(文件+目录)(chmod 2XXX chmod g+s)

    对于二进制文件

    要求其他权限至少为x,为了安全性,没有执行权限当然不让你其他了

    用户执行该二进制文件时暂时拥有用户组的权限

    1. 对于目录

      要求用户至少能进去目录,所以至少为rx权限,此时用户暂时属于目录的本用户组,比如新建一个文件,,其用户组认为原来的目录用户组

  3. Sticky Bit(一般只对目录设置)(chmod 1XXX chmod o+t)

在一个目录上设了sticky位后,所有的用户都可以在这个目录下创建文件,但只能删除自己创建的文件(root除外),这就对所有用户能写的目录下的用户文件启到了保护的作用。