Do you have a requrement to protect some critical files in your linux machine, even from the root users?. Well, if you do, then here is a command that might help you. This command just lock the file and even a root user can’t delete it or write on it. Read on to know more.
chattr is a linux command that protects the file using extended file system ‘i’ attribute. Once the command is executed, the file can’t be written, deleated nor linked, even by the administrators. You can do this as below.
chattr +i filename
Now, the file is locked. Try to delete it or write into it as a root user. You can’t.
You can verify the protection by using “lsattr” command, and you should see the output that proceedes.
lsattr filename—-i———— filename
Here is how you remove the lock.
chattr -i filename
You can now delete and write the file as you wished.
If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!