除了那9个权限外,还有一部分的隐藏属性。这些隐藏属性虽然不常用,但能对系统的安全性有很大的帮助
1. 属性介绍
对文件以及目录的作用不同,两者的规律同正常的权限一样,只要记住:语句是文件的内容,文件名是目录的内容
-
a:使文件只能追加内容,而不能删除或修改内容,也不能删除、重命名、硬链接、修改权限,但可以软链接;使目录只能增加子文件或子目录,而不能删除子文件或子目录,但限制只针对该目录下的第一级。
只有 root 用户才能设置该属性。
ps.该权限可用于日志文件,防止恶意删除日志文件或日志内容,同时又不影响日志的正常记录
对文件本身进行操作:
[root@localhost ~]# chattr +a test-a # 为 test-a 文件加入 a 权限
[root@localhost ~]# lsattr
-----a---------- ./test-a
[root@localhost ~]# rm test-a -f # 删不掉
rm: 无法删除"test-a": 不允许的操作
[root@localhost ~]# mv test-a test #移不动
mv: 无法将"test-a" 移动至"test": 不允许的操作
对文件内容进行操作:
[root@localhost ~]# cat test-a # 文件内容是 1 行数字
11
[root@localhost ~]# vim test-a # 使用 vim 添加一行新的数字。
11
22
~
~
"test-a"
"test-a" E212: Can't open file for writing #失败!
Press ENTER or type command to continue
## 说好的能追加呢?请使用下面的方法!
[root@localhost ~]# lsattr ; cat test-a
-----a---------- ./test-a
11
[root@localhost ~]# echo 22 >> test-a ; cat test-a # 成功了!!!
11
22
-
i:比a更严苛,连追加都不让了,其他限制与a相同。同样也只有 root 用户能设置该属性
[root@localhost ~]# cat test-i
11
[root@localhost ~]# echo 22 >> test-i # 追加都不让了!
-bash: test-i: 权限不够
2. 设置、查看的方法
设置:
chattr [+-=] [ia] <file or dir>查看:
lsattr [-adR] <file or dir> # 选项的功能同 ls 命令的选项相同