Introduction
The command chattr can change file attributes on a Linux file system (extended file system or ext). Therefore, by assigning the "IMMUTABLE" attribute to a file with chattr, it cannot be modified, deleted, or renamed. It will also be impossible to create a link to this file or write data to it.
Only the user root or a process with the "CAP_LINUX_IMMUTABLE" capability can set or reset this attribute.
How to Use chattr
Using the chattr command to lock a file is quite simple. Let's take the file "/root/bloqueado.txt" as an example. To lock it, add the IMMUTABLE attribute, using the following syntax:
# chattr +i /root/bloqueado.txt
It can no longer be manipulated; this will only be possible by removing the IMMUTABLE attribute that was added.
To unlock the file and allow changes, simply remove the attribute:
# chattr -i /root/bloqueado.txt
Remember, if you have questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We're here for whatever you need. Get in touch!