To make a file on a Linux system read only use the following:
#add protection
chattr +i filename
This will ensure nothing can change the file unless it removes the chattr bit prior to writing to the file. If you need to update the file run:
#remove protection
chattr -i filename
This will enable editing so you can make changes. However, be sure to reset the file as read only once you’re finished to ensure the file doesn’t change. This is extremely useful with cpanel and other systems that change system files and reset them to defaults each time the service is restarted. It will allow you to implement customizations without them being overwritten every time a service restarts.