If the write permission of the file is disabled, no one can change the file.
The chattr +i FILE
also can protect the file from change.
Let me know what the difference, and when we should use chattr +i
rather than chown -w
.
chattr (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in Linux system to secure accidental deletion or modification of important files and folders, even though you are logged in as a root user. In Linux native filesystems i.e. ext2, ext3, ext4, btrfs, etc.
To make the files immutable, “chattr” command can be used. The filesystems in Linux ext2, ext3, ext4, btrfs supports all the flags, however all the flags won't support all non-native FS. One cannot delete or modify file/folder once attributes are sets with chattr command, even though you have full permission.
An immutable file cannot be changed or renamed. An appendOnly file allows append operations, but not delete, modify, or rename operations. An immutable directory cannot be deleted or renamed, and files cannot be added or deleted under such a directory.
The command below makes /backups/passwd file immutable (or undeletable). This implies that the file can't be modified in any way: it can't be deleted or renamed. You can't even create a link to it and no data can be written to the file as well.
chattr +i
sets the immutable
filesystem attribute on the file. It differs from access control rules. Access control rules apply to the file attributes, while immutable
is a filesystem extended file attribute, which may not be available on all filesystems. Only a user with root privileges can set or unset this extended attribute. Nobody, not even the owner or a user with write permission, can write into such file. A user without write file permission can create a hard link to a regular file, but if the file is marked as immutable, a user cannot create a hard link, since the filesystem cannot change the references count to this immutable file.
chattr +i
is useful for protection from accidental deletion by root. Also an immutable file cannot be renamed or moved from one directory to another.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With