Prevent deletion of folder but let access to everything inside of it

1

1

I know there is the +i flag for files and directories, but i have a deeper Problem.

Is there a way to prevent a folder from being deleted by an User which should be able to create / access / remove files and folders INSIDE the delete-protected folder?

The sudo chattr +i testfolder flag wont help because then a user can only read files, but not create or delete these.

The sudo chattr +a testfolder flag wonth either help because then a user can write and read files, but only append edit files and dont remove them.

I need a solution where a user is able to write, access and remove Files but can't delete the root/parent folder.

fechnert

Posted 2016-02-15T11:40:32.687

Reputation: 115

Answers

3

The deletion of a directory depends on the rights of its parent directory and not its own rights. If the user have write permission to the parent, then the directory is deletable, otherwise not.

So if the user does not have to have the permission to create or delete directories/files at the same level where the directory to protect is, then this should work:

chmod 755 /the/parent/dir 

If some users still must be allowed to modify the parent's content, then the parent should be owned by a group whose members are those users and that group should have the write permission:

addgroup bigguys
chgrp bigguys /the/parent/dir
chmod 775 /the/parent/dir

Gombai Sándor

Posted 2016-02-15T11:40:32.687

Reputation: 3 325