0

This is what I think is happening.

In Unix the ability to delete a file is governed by the writeability of the directory that it is in. This ultimatly affects the writeability of the file. As a file can be deleted and replaced.

I can set the stick bit. This helps a bit, but is ignored for the owner of the file.

I realise that ultimately any permission can be changed by the owner. But is there a way to stop a file being deleted, in the absence of changing permission (by accident)?

I am interested for solutions, for Gnu/Linux. However if there is no solution for this one, then I would be interested in solutions for any Unix, including fringe variants (plan 9, mac-os, bsb, solaris, athena, etc. etc. ….).


Immutable bit chattr +i file, can only be set by user with CAP_LINUX_IMMUTABLE e.g. root (So is not very useful).

1 Answers1

0

Currently, Linux inherits standard Unix "rwx" access controls. This means that without serious redesign of current permission model it is not possible to deny file owner to remove the file, albeit kernel is able to restrict that. (kernel does manage your files, and can deny any user activity, but current kernel has too little permission bits to control on)

If not root user, then you can try set mode for owner only, for example, chmod 444 file. Note that you have each time to set write bit back to modify it. And some software (like vim) can automatically reset that bit without any notice, but by default it does not do that.

Immutable flag does help only if you have a mechanism - sudo or like, which gives you permission to change it as unprivileged user.

See also Are there more advanced filesystem ACLs beyond traditional 'rwx' and POSIX ACL?. ACLs (not POSIX) can solve this issue by defining remove permission.

  • The question asks about Unix (that's not the same as Linux). Your Linux-specific answer is incomplete, in any case. – Thomas Dickey Jul 03 '16 at 13:53
  • But then addition about immutable Linux feature implicitly includes Linux-specific details there. Otherwise I even would not include the Linux details. –  Jul 03 '16 at 18:00
  • I am interested in solutions for an Unix, including Gnu with or without Linux kernel. (I use Debian Gnu with the Linux kernel, so is the one I am most interested in, but if there is no solution for this one, then I would be interested in solutions for any Unix, including fringe variants (plan 9, mac-os, bsb, solaris, athena, etc. etc. ….). – ctrl-alt-delor Jul 03 '16 at 21:10
  • I updated my answer –  Jul 04 '16 at 03:35