Q. How do I write protect file under Linux so that no one can modify it?
A. You need to use chattr command, which changes the file attributes on a Linux second extended file system. The chattr command supports various attributes.
A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute in other words you make a file unchangeable or unalterable.
For example if you want file /data/financial.txt unchangeable by anyone on your system, type the following command (login as the root user):
# chattr +i /data/financial.txt
Now no one can delete or modify file /data/financial.txt. To reset back permission, type the following command:
# chattr -i /data/financial.txt
Use lsattr command to lists the file attributes on a second extended file system. It is use to see attributes set by chattr command.
# lsattr financial.txt
- Linux Password trick using chattr command
- FreeBSD: How to write protect important file (even root can NOT modify/delete it)