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.
1 Answer
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– j2emanueJan 14, 2017 at 0:49
-
-
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 )?– j2emanueJan 14, 2017 at 1:03
-
Yes, that would work. Requiring sudo access was the point, after all. Jan 14, 2017 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.– j2emanueJan 14, 2017 at 1:12