-2

I want to have a user who can write files; but I don't want this user to be able to delete them.

JdeBP
  • 68,745
  • A sample use case would be helpful. Do they need to be able to edit existing text or just append? If they can edit then they could technically just delete everything in the file and leave it blank. – Zachary Brady Nov 10 '16 at 18:50
  • Why is this downvoted so much? I learned something from the answer that I didn't know previously... – user000001 Nov 10 '16 at 19:45
  • It's being down-voted because it's basically a duplicate question of something that's already been answered, in depth on this site. – Thomas N Nov 10 '16 at 19:49

1 Answers1

4

You probably want to use the chattr command to set this attribute for files owned by the user in question. Example:

chattr +a some_file

Will keep the user from deleting the existing contents and opens the file in append mode for writing. Unfortunately, there isn't any inheritance for these extended filesystem attributes, so you'll have to explicitly set them for all files you need to be handled in that manner. See the man pages for chattr for more information. See also What is the effect of "chattr +a" on a directory if you'd rather search SE.

Thomas N
  • 744