0

How to prevent a user from deleting the folders and files on his own home directory? In my scenario user can create & modify the folders but user should not delete them. How could we achieve this?

2
  • 3
    How about telling us what you want to achieve on a higher level, rather than already suggesting an unfeasible approach to solve what you want to achieve. In other words, what is the reason why you want to prevent deletion? Do the files have to exist physically at all times for some reason? Or do you just want to prevent accidential data loss? Depending on this, there may be other solutions to your scenario than access rights. – Run CMD Mar 13 '15 at 8:19
2

Deleting a file requires write permissions to the file's parent directory. The same permissions you would need to have to be able to create files in the directory in the first place, so your requirements are conflicting: removing write permission to the user's homes to prevent deletion also prevents creation of files.

Note that file creation and file deletion are very similar: in both cases you are changing the entries in a directory, whether by adding or removing an entry.

0

If you really wanted to, I suppose you could manually make important existing files immutable with the following:

$ chattr +i filename

This will add the i attribute to the file, which would prevent anyone from modifying or deleting it in any way. You can check if a file is immutable as such:

$ lsattr filename
----i--------e-- filename

If the i tag is present, it is immutable. To remove it, use:

$ chattr -i filename

NOTE: you have to be root to add or remove the immutable tag to files.

The downside to this, of course, is that you'd have to go and do this manually for all the files you want to be protected from deletion. The upside is, it does not prevent a user from creating new files.

1
  • 1
    But it prevents the user from editing the file. – Run CMD Mar 13 '15 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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