How to make a Linux File unchangeable ( unalterable ) so that no one can modify it

by on April 19, 2006 · 1 comment· LAST UPDATED March 5, 2008

in , ,

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
Output:

----i------------ financial.txt

See also:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 Kevin June 13, 2008 at 8:08 pm

How do you do this in a jffs2 file system?

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: