If for some reason you need to prevent the modification of any file in your system, this article is for you.The reasons are different, I have heard that sometimes the system (or some other program) change some sort of config file and you have it each time to recover. Or you are afraid that your child will change some important file, such as the config of your favorite game (CS:GO)… There are a lot of application options.
Today we will talk about the chattr command. Yes, similar functionality can be achieved in the usual chmod and chown, but still with the good old chattr prohibit any file to be subjected to any changes can be more effective. And no matter who tries — you, the administrator, or the system itself — no one can affect the contents of this file!
Chattr itself is very versatile. It is designed to manage the attributes of the file, and has a fairly wide range of tools, but today we are interested in how to prevent the file from changing.
Let’s create a file! Open the terminal in the home directory and execute:
This will create a text file named «unchangeble.txt». We’ll need it for experiments.
The following command propose to add some text. For example, «MintGuide.org — Hello from Mr. Shekin». Do this in a text editor or run a command like this:
Let’s forbid anyone to change it!
Now you can try to delete it. Not deleted! Even through sudo! Even from root! You also won’t be able to rename the file or make changes to its contents.
If you want to make the file editable again, just run:
May the Force be with you,