bubbl
Posts: 85
Joined: Sun Jul 14, 2013 9:15 pm
Location: United Kingdom
Contact: Website

Protecting files/folders from unwanted deletion

Sat Nov 30, 2013 6:09 pm

Protecting files from unwanted deletion is very important security on the tasklist of Unix Administrators. On Linux boxes you can use the chattr command and that works ine on all my Ubuntu based servers.

Let’s give you some examples how chattr work under Linux:
To make a folder undeletable, run:

Code: Select all

sudo chattr +i -R foldername
After that, you can’t delete, rename or do anything with this folder. But if you don’t need this folder anymore or you’ve got to apply some changes to it run:

Code: Select all

sudo chattr -i -R foldername
To make a file undeletable, run:

Code: Select all

sudo chattr +i filename
To be able to change or delete the file, run:

Code: Select all

sudo chattr -i filename
We're not here because we are free. We're here because we are not free. There is no escaping reason. No denying purpose. Because we both know without purpose, we would not exist.
http://www.bartbania.com/

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Protecting files/folders from unwanted deletion

Sat Nov 30, 2013 6:24 pm

I prefer chmod myself it has more flexibility over chattr imo. :)

Richard S.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Protecting files/folders from unwanted deletion

Sat Nov 30, 2013 6:28 pm

redhawk wrote:I prefer chmod myself it has more flexibility over chattr
Non sequitor. The point of chattr is to protect it even against root.

Note: Yes, I know it's not foolproof as a truly malicious person or program can just "un-chattr" it and then delete it. But it is a step in the right direction.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Protecting files/folders from unwanted deletion

Sun Dec 01, 2013 2:59 am

Joe Schmoe wrote:
redhawk wrote:I prefer chmod myself it has more flexibility over chattr
Non sequitor. The point of chattr is to protect it even against root.

Note: Yes, I know it's not foolproof as a truly malicious person or program can just "un-chattr" it and then delete it. But it is a step in the right direction.
If someone malicious get access to your system then all bets are off. chattr is good protection against finger trouble.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Beginners”