How can I disallow a user from moving/renaming a subdirectory of this home directory?

Even if a user doesn't have any rights on a directory, it can rename/move it as long as the source and destination parent directory are writable.

I had a similar problem on macosx. Users inadvertently drag&drop the "Library" folder somewhere else breaking everything as there are applications depending on that path.

I don't it would be better to depend on another path, outside the home dir, or use ".files" but I have a legacy situation.

I tried to fix the problem my putting the dir somewhere else and then making a "bind" mount

mount -o bind sourcepath /home/user/somedir

It prevents the renaming of the dir:

mv: cannot move `somedir' to `somethingelse': Device or resource busy

Does anybody know an easier way?


Easiest is probably using chattr:

sudo mkdir /home/user/somedir
sudo chown root:root /home/user/somedir
sudo chattr +i /home/user/somedir
  • Does this require mounting with extended attributes? Does Ubuntu mount with xattrs by default? – Ryan C. Thompson Nov 1 '10 at 19:04
  • ok it solves the problem for me since I don't have to let the user create direct children in this directory – ithkuil Nov 1 '10 at 19:05
  • Ubuntu mounts with xattr by default, but not user xattrs. – Kees Cook Nov 1 '10 at 19:13
  • does this work with acl (access control lists) as well? – RolandiXor Nov 1 '10 at 19:16

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.