0

Given this directory structure:

/parent
    /a
    /b

Can I prevent the "parent" folder to be removed/renamed/changed permissions by any user other than root, while the user "bob" could freely add/delete/edit files and folders inside it? Like removing "a", renaming "b", creating "c"... but nothing on "parent".

Thank you

1 Answer 1

0

You'll utilize chmod and chown to accomplish this:

# Nested Files and Directories #
  chown -R bob:bob /parent/*
  chmod -R 760 /parent/*

# Parent Directory #
  chown root:root /parent
  chmod 750 /parent
4
  • After I ran these commands, bob cannot cd to /parent anymore. Which is normal as he cannot execute it. I need bob to be able to cd to /parent, as well as create/delete directories and files in /parent. Just, he shouldn't be able to edit /parent itself
    – Ninj
    Sep 7, 2019 at 14:46
  • @Ninj I can't boot up a VM at the moment to test, but you should be able to play around with the permissions of /parent to get the desired access. Try chmod 755 /parent. Let me know if that works and I'll update my answer =]
    – JW0914
    Sep 7, 2019 at 14:55
  • I tried chown root:bob (because bob is in the "bob" group): it can cd, but cannot mkdir. I tried chmod 755: same result. I think that a user can mkdir only if the current directory gives him write access. But I don't want that because I don't want the user to delete /parent
    – Ninj
    Sep 7, 2019 at 15:00
  • @Ninj The only workaround I've found thus far is to created an additional nesting within /parent (i.e. /parent/1/a, /parent/1/b, etc.) and have bob work out of the nested folder /parent/1. If this is an acceptable solution, I'll edit my answer accordingly.
    – JW0914
    Sep 7, 2019 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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