We have a directory and want to protect that from remove and rename, but we need to be able to rename, remove and create contents. What we can do?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I guess this is not possible with standard Linux technology. You need RichACLs to configure precisely that.
If the side effects are not a problem then you can remove write permissions from the parent directory.
OK, I have to correct my first thought: There is a work-around with standard features. You can move that directory to a different path, create an empty directory with the same name and without any write permissions in its place and make a mount --bind from the new position to the old one. Active mount points cannot be deleted but the content permissions are not affected.
Method 2
Permission to remove and rename a directory is determined by its parent’s permissions, not its own (just like other files). Just set the permissions on the directory to what you need and make its parent -w.
Depending on your use case you may want to make the directory sticky +t as well – then users can’t move around others’ files, only their own.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0