3

I have a directory called "development" and I want to set its permissions I guess, in a way that if someone where to run rm -rf development it would prompt for sudo access or just deny the command, implying sudo access required. How can this be done? Right now, the folders inside of this can be deleted safely, but not from the development folder itself.

3

If you want to require sudo use to delete it, you need to make the directory and perhaps all the files inside it be owned by root with chown:

chown -R root development

To protect the directory alone, make a root-owned file inside it:

sudo touch development/.no-delete
sudo chown root development

That will prevent anybody deleting the directory without root access even if it's otherwise empty.

Just changing permissions on the directory won't help, because deleting the directory depends on permissions of the parent directory. Changing permissions on the directory will affect deletion of its children, rather than itself. The non-root owner would also be able to change the permissions regardless.

  • I tried the second option as its not recursive and the sudo part ran fine, but i get the following error when trying to chown: chown: Development: Operation not permitted. The permissions on the directory look like this: drwxr-xr-x – j2emanue Jan 14 '17 at 0:49
  • Changing ownership requires root too. – Michael Homer Jan 14 '17 at 0:51
  • so am i able to run sudo chown root development (do you think that would work or do i actually have to be the root user )? – j2emanue Jan 14 '17 at 1:03
  • Yes, that would work. Requiring sudo access was the point, after all. – Michael Homer Jan 14 '17 at 1:06
  • now i cant access the directory though. Isn't there a solution where i can still access the directory after changing owner. – j2emanue Jan 14 '17 at 1:12

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.