1

I'd like to know if I can create a file on a server that has all directories set to 777 permission, such that the no ordinary user (non-root) is able to delete the file. If so, do I have to be root user on the system, or can I do it as an ordinary user too?

My initial thoughts are, I should just be able to use "chmod 0444" on the file and that should take care of it.

I would have tried this out myself but I don't have access to a Linux server.

  • I wonder if there is a use case to this? Why not just deal with it by setting the directory permissions to something, less wide-open? – ilkkachu Mar 22 '17 at 22:10
  • @ilkkachu take /tmp as an example. This folder is accessible for any user in a system. But it's undesirable for one user to delete temp files of other users. Then this problem arises. – ddnomad Mar 22 '17 at 22:53
  • @ddnomad, well, my point was mostly on the "all directories" part. – ilkkachu Mar 22 '17 at 23:18
5

You may add the “sticky bit” (with chmod +t) to your directory. With this bit set, files in the directory can only be deleted by their owner.

You may also give the file the “immutable” attribute (with chattr +i). With this attribute, nobody can modify or delete the file.

  • @AutomationZombie Just curious, did you choose the “sticky bit” or the “immutable” attribute? – user2233709 Mar 23 '17 at 17:43

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.