Permissions can only go so far to prevent a file from being written.
There are some cases where you just want a file to be locked, preventing anything else from changing it.
Most file systems offer tools to do just that.
Let's use a filename example:
For CentOS and Debian, the most command is chattr. To lock a file, type:
chattr +i /path/to/file.txt
and to unlock it, use:
chattr -i /path/to/file.txt
To check if a file is locked or not, type:
The "i" in this case refers to the word "immutable", to be unchangeable over time, so you'd see the 'i' in the list of other flags (usually just many ---- characters) if it's locked.
FreeBSD has it's own tools, as chattr is not available. To lock a file, you'd use:
chflags schg /path/to/file.txt
To unlock the file:
chflags noschg /path/to/file.txt
and to view if it's locked:
ls -lo /path/to/file.txt
where the "schg" will show up in the list if it's locked.