Denny
Denny

Reputation: 459

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

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?

Upvotes: 13

Views: 8819

Answers (3)

BraveNewCurrency
BraveNewCurrency

Reputation: 13065

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

Upvotes: 25

Dharmanshu Kamra
Dharmanshu Kamra

Reputation: 613

you should have root perms

sudo chattr +i file

Upvotes: 4

traxs
traxs

Reputation: 306

You can use Perl or another language to create a file lock

How do I lock a file in perl

But, root could kill the process can gain access to the file.

Upvotes: 0

Related Questions