If I would like to lock a file as read-only. Even root can not use an editor to modify it, just allowing any program to open it read-only.
Any suggestions?
You need to set the user to be the owner chown -R <username> <foldername> (-R operates recursively) then set the permissions to be read only for just the user chmod -R 400 <foldername> . Root will be able to read and write the files regardless of the permissions set.
There is an "immutable" bit for files.
Programs (even running as root) won't be able to tamper with the file. Of course, root can un-do the bit, but most programs (especially non-malicious ones) won't get past it.
Set it with
sudo chattr +i file
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