![]() ESN 37441-091026-291542-80 |
|
Document Name: Prevent deletion or moving of files Document Description: Prevent deletion or moving of files2009/10/26You need to let users create files in a common directory, but you don't want them to be able to delete other's files. Or you've put certain files, directories or symlinks into a user's home directory and don't want them to be able to mess with any of those. What can you do? "t" bitIf you create /foo and do "chmod 1777 /foo", you'll have a world-writeable directory with the "text bit" set. Any user can create files here, but they can only delete files that they own (root can still rm anything). That's ownership as listed in the "owner" column of an "ls -l". Group ownership doesn't come into play here although it does change responses a bit. Let's see what happens when Sam tries to remove Pete's files in a directory with the text bit set: Now watch what happens when a user in the "wheel" group does the same thing: Having write permission makes rm proceed without caution, only to be brought up short by the restrictions of the "t" bit. mount --bindIf the problem is removal of a directory and it is not terribly inconvenient for you to have that directory actually be on a separate filesystem, then "mount" can make the directory safe from removal. You can read more at mount --bind, but it's not very complicated. Let's say we have /dev/foo mounted at /foo and I want a "link" to that under /home/fred. All I have to do is: mount --bind /foo /home/fred/foo
Fred can have full write permissions on /foo if he needs it, but he will not be able to remove /home/fred/foo. Not even root can:
Now THAT is removal protection! ACL'sTypically, ACL's let you avoid complicated groups by setting specific permissions for specific users. Other than setting a file as "immutable" (chattr +i filename on some Linuxes), you really can't prevent removal of a file. Of course setting it that way may also make it useless, as even the owner can't modify or remove it either without doing "chattr -i" first.. See ACL's for more on that. Author: Anthony Lawrence - Contact Author Publisher: Anthony Lawrence Licensee Name: Anthony Lawrence Reference URL: http://aplawrence.com/Unixart/file-removal.html Copyright: All Rights Reserved Registration Date: 10/26/2009 11:37:18 PM UTC Views: 632 |
