Linux-chattr-lsattr-隐藏权限

3.文件管理

本章同步视频:https://edu.51cto.com/sd/e4874


3.3.2 隐藏权限

1.查看隐藏权限

(1)隐藏权限的效果

[root@localhost tmp]# ll aaa

-rw-r--r--. 1 root root 6 Mar 13 21:33 aaa

[root@localhost tmp]# echo "bbbb">aaa

-bash: aaa: Operation not permitted

#注:文件的拥有者且为root,明明具有写权限,却不能向aaa中写入数据。

(2)查看隐藏权限

[root@localhost tmp]# lsattr aaa

-----a---------- aaa

2.设置隐藏权限

(1)设置a属性:不能写入,只能追加

[root@localhost tmp]# cat aaa

aaaa

[root@localhost tmp]# chattr +a aaa

[root@localhost tmp]# echo "bbbb">aaa   

-bash: aaa: Operation not permitted          #写入失败

[root@localhost tmp]# cat aaa

aaaa                                                           #aaa的内容未发生变化

[root@localhost tmp]# echo "bbbb">>aaa   #追加内容成功

[root@localhost tmp]# cat aaa

aaaa

bbbb                                    #aaa的内容被追加了bbbb

(2)取消a属性

[root@localhost tmp]# chattr -a aaa

[root@localhost tmp]# cat aaa

aaaa

[root@localhost tmp]# echo "bbbb">aaa

[root@localhost tmp]# cat aaa

bbbb

(3)设定i属性,不能写入,不能追加,不能删除

[root@localhost tmp]# chattr =i aaa

[root@localhost tmp]# cat aaa

aaaa

bbbb

[root@localhost tmp]# echo "cccc">aaa

-bash: aaa: Permission denied

[root@localhost tmp]# echo "cccc">>aaa

-bash: aaa: Permission denied

[root@localhost tmp]# rm -f aaa

rm: cannot remove ‘aaa’: Operation not permitted


上一篇:linux文件的隐藏权限——chattr、lsattr


下一篇:linux基础(四)---lsattr和chattr