这个工具对于系统管理员来说非常重要,可以保护重要文件不被任何其他用户滥用。
“chattr”实用程序可用于保护重要文件系统,例如
- hosts.allow 和 hosts.deny
- /etc/hosts
- /etc/ssh/*
- /etc/xinetd.d/*
注意:一旦我们将 '+i ' 属性添加到任何文件,甚至 root 用户也将不被允许对该文件进行任何更改,除非我们使用 '-i ' 更改该属性
用法:
# chattr +i "filename"
在这里使用 +i 我们可以添加或者覆盖此属性到文件,根据该属性,除非 root 用户恢复更改,否则任何用户都不能再修改此文件。
# chattr -i "filename" Using -i you can remove the attributes from the file.
查看文件的属性
# lsattr "文件名"
例子
# chattr +i /etc/hosts
# lsattr /etc/hosts ----i--------e- hosts
这里“i”显示提供的当前属性,“e”属性表示文件正在使用范围来映射磁盘上的块。
这是 ext4 文件系统的默认设置,无法使用 chattr 删除。
现在,当我们尝试进行任何更改时。
# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain 10.10.10.xx server server.example.com . . "hosts" [readonly] 3L, 186C
因此,即使对于 root 用户,该文件也已变为只读,因此现在具有 root 权限的用户也将不允许对此文件进行任何更改。
如果要删除属性
# chattr -i /etc/hosts # lsattr /etc/hosts ------------e- hosts
日期:2020-06-02 22:18:31 来源:oir作者:oir