LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (http://www.linuxquestions.org/questions/linux-security-4/)
-   -   Question about permissions (http://www.linuxquestions.org/questions/linux-security-4/question-about-permissions-4175430980/)

jmvidalvia 10-07-2012 11:55 AM

Question about permissions
 
Hi,
Still wondering how I could delete a directory if I had no writing permisions.
There's something I am missing: OK, I (as jmd user) have writing rights into the present directory, but what about those files/folders I don't own, like mnt/ in the attached case?
Code:

jmd@debian3:~$ ll
total 44K
4,0K drwxr-xr-x 3 jmd  jmd  4,0K oct  6 17:30 .
4,0K drwxr-xr-x 4 root root 4,0K oct  3 16:42 ..
4,0K -rw-r--r-- 1 jmd  jmd  3,3K oct  6 17:30 .bashrc
4,0K drwxr-xr-x 2 root root 4,0K oct  3 16:56 mnt
jmd@debian3:~$ rm mnt/ -r
rm: żborrar el directorio «mnt»  protegido contra escritura? (s/n) s
jmd@debian3:~$ ll
total 40K
4,0K drwxr-xr-x 2 jmd  jmd  4,0K oct  7 18:44 .
4,0K drwxr-xr-x 4 root root 4,0K oct  3 16:42 ..
4,0K -rw-r--r-- 1 jmd  jmd  3,3K oct  6 17:30 .bashrc
jmd@debian3:~$

Thanks!

pixellany 10-07-2012 01:14 PM

I think you can remove a directory/file if you have execute permission AND execute and write permission in the parent directory.

jmvidalvia 10-07-2012 04:13 PM

Quote:

Originally Posted by pixellany (Post 4799571)
I think you can remove a directory/file if you have execute permission AND execute and write permission in the parent directory.

Thanks!

frob23 10-07-2012 05:25 PM

The answer you were given is correct but I just wanted to explain the reasoning behind this a little bit more so the reasoning behind it makes sense.

If you (joe) have a folder in your home directory (quux) owned by root, and you have no permissions to access this directory, you may be able to delete it.

A directory is really just a special file. It holds a list of files (and directories) in it. If you have write and execute permissions to a directory, you can make changes to its contents. This means you can delete any references to files or directories -- even if you don't own them or otherwise have access to them. You can't "change" them or even read them but you can change the "file" you do own (the directory) and remove the reference to it.

Now, there is an exception to this. The directory must be empty for you to delete it. If quux has nothing in it, you can remove it. If it has a file in it, you won't be able to remove it because you can't delete directories that are not empty and you don't have the sufficient permissions to edit the contents of that directory.

For files in a directory you have the above mentioned access in, you can override the permissions and delete them pretty much at will.

If you have write and execute permissions for a directory, you can make changes to the contents of that directory regardless of the permissions on the objects themselves (aside from directories that aren't empty).

jmvidalvia 10-10-2012 05:03 PM

Cristal clear. Thanks frob23 for your explanation.


All times are GMT -5. The time now is 11:43 AM.