0

I'm interested in protecting a parent directory (e.g., test in the example below) by being removed (i.e., accidentally, without explicit root priviledges), while at the same time I need to be able to write inside it (as a non-root user).

For instance, suppose that we have a parent directory test with the following sub-directories:

test/
|-- dir_1
`-- dir_2

Let's suppose that root is the owner and the group is some_group:

drwxr-xr-x 4 root       some_group 4096 Apr 16 13:38 .
drwxr-xr-x 3 some_user  some_user  4096 Apr 16 13:36 ..
drwxr-xr-x 2 root       some_group 4096 Apr 16 13:38 dir_1
drwxr-xr-x 2 root       some_group 4096 Apr 16 13:38 dir_2

Now, I want a user who is member of some_group not to be able to remove dir_1 and dir_2, which I believe I've guaranteed by setting them to 755, but at the same time I need this user to be able to write inside test, but without being able to delete the whole test directory. Is there any way of doing this? Thank you.

2

You need to realize that in Unix file systems, you don't need write permission on the target to delete an entry, just on the containing directory.

If you want to protect the directory test, set the permissions on the parent of test.

If you want to allow users to create and delete their own files, set the permissions on test to 1777. The high bit is called the sticky bit.

1
  • Thanks, it did the trick (I didn't know about the sticky bit). – nullgeppetto Apr 16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.