Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In GNU/Linux, how can directories be set such that the owner can only add/read files/directories to/from them but only a super user can do any deletion in that structure?

Consider this scenario: You are rsyncing some files and directories you own to a directory. You want to be able to write to that directory (and later, when updating the backup---i.e., rsyncing again---write to all of the subdirectories, too) but you don't want to be able to delete anything in this structure, unless you are a super user.

The restricted deletion flag t in chmod does not help in this situation, because it restricts deletion by non-owners.

Setting the mode to u=rX,go= for the files and directories (while transferring using rsync) does not help either, because later rsyncing will not be possible unless the w mode bit is added to all of the directories on the receiver before starting the rsync and that will be very time consuming.

Is ACL the way to go here?

Update: Even with ACL I don't see a way to do this.

share|improve this question

3 Answers 3

Check out our good friend chattr. If you're using an ext2/3/4-based FS, you can set the immutable or undeletable bit, and not even root can delete the file until you unset the corresponding bit.

share|improve this answer
    
The question seems to require that the files remain modifiable (in order to update the backup). –  grawity Jul 5 '11 at 15:36
    
Good catch. chattr may not be the best choice to satisfy all requirements. –  cwawak Jul 5 '11 at 17:27

You may somehow do this using sticky bits.

$ mkdir drop_box
$ chmod 777 drop_box
$ chmod u+s,g+s drop_box
$ ls -l
total 4
drwsrwsrwx    2 tclark   authors      4096 Sep 14 10:55 drop_box

Now anyone can move files to this directory but upon creation in drop_box they will become owned by tclark and the group authors. This example also illustrates how you can change multiple levels of permissions with a single command by separating them with a comma. Just like with the other permissions this could have been simplified into one command using the SUID and SGID numeric values (4 and 2 respectively.) Since we are changing both in this case we use 6 as the first value for the chmod command.

$ chmod 6777 drop_box/
$ ls -l
total 4
drwsrwsrwx    2 oracle   users        4096 Sep 14 10:55 drop_box

Totally not sure if this will help you reach your goal, as I cannot think of the proper permissions to give the files and directories for your example to work. I just posted this in case you have nothing else to go on.

Good-luck.

share|improve this answer
    
The point in my question is to not have the owner changed. –  Omid Jul 4 '11 at 21:29

You cannot do that in a standard Linux environment. You may be able to write a rule for SELinux or Tomoyo or whatever, to forbid file deletion, but this will not stop the user from overwriting the file with garbage data or truncating it entirely, whether intentionally or not.

share|improve this answer

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.