26.root用户无法删除的文件

root用户无法删除的文件

文件/目录添加chattr扩展属性后会影响文件的操作。

如:

a权限:让文件/目录只能追加内容,没有删除或修改权限

i权限:让文件/目录不能新建和删除,仅拥有修改的权限

 

chattr +i 文件/目录

[root@localhost dir_file]# chattr +i dir_inner/

[root@localhost dir_file]# ll

total 0

drwxrwxr-x+ 2 root root 6 Dec  4 14:03 dir_inner

[root@localhost dir_file]# rm -rf dir_inner/

rm: cannot remove ‘dir_inner/’: Operation not permitted

 

chattr +a 文件/目录

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

[root@localhost dir_file]# rm -rf test.txt

rm: cannot remove ‘test.txt’: Operation not permitted

[root@localhost dir_file]# echo "22222222">>test.txt

[root@localhost dir_file]# cat test.txt

22222222

 

lsattr 目录

查看chattr扩展属性权限

[root@localhost dir_file]# lsattr test.txt

-----a---------- test.txt

 

chattr -i 文件/目录

[root@localhost dir_file]# chattr -i dir_inner/

chattr –a 文件/目录

[root@localhost dir_file]# chattr -a test.txt

posted @ 2020-12-28 08:35  AI非AI  阅读(201)  评论(0)    收藏  举报