Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a file permanently read-only on Linux so even root can not edit it?

Tags:

linux

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?

like image 662
Denny Avatar asked Aug 01 '13 03:08

Denny


People also ask

How do I make a file read only by root Linux?

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.


1 Answers

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
like image 162
BraveNewCurrency Avatar answered Oct 20 '22 13:10

BraveNewCurrency