Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I make some file impossible to be deleted by user even if it is under his/her home folder?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

It is possible to make a file impossible to delete, even from root, on an ext2/3/4 filesystem, changing a file system attribute of the file:

$ cd
$ touch dummy
$ sudo chattr +i dummy
$ rm dummy
rm: remove write-protected regular empty file `dummy'? y
rm: cannot remove `dummy': Operation not permitted
$ sudo rm dummy
[sudo] password for enzotib: 
rm: cannot remove `dummy': Operation not permitted
$

More information on chattr and lsattr manual pages.

If later you want to delete the file you should use

sudo chattr -i dummy

before using rm.

There are two drawbacks to this:

  1. you have to be root to change attributes;
  2. you can forget about the attributes of that file or the way to change them, so that it seem you cannot delete the file anymore.
share|improve this answer
    
Worked perfectly! Thank you so much. –  desgua Apr 5 '11 at 14:43
    
Is there a way to use this and maintain other permissions? For example, still allowing the user and group permissions for rwx of sub-directories and files. –  roydukkey Apr 8 at 18:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.