[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Something weird about file permissions

On Tue, Mar 31, 2009 at 7:56 PM,  <mylists@montblanc.homeip.net> wrote:
> Hi guys! Something is very weird or I didn't sleep enough last night. I am
> puzzled. How can an ordinary user delete a file he has no write access?
> See this example:
> pep@montblanc:~$ cd /tmp/
> pep@montblanc:/tmp$ mkdir test; cd test
> pep@montblanc:/tmp/test$ sudo touch file_owned_by_root
> pep@montblanc:/tmp/test$ ls -l file_owned_by_root
> -rw-r--r-- 1 root root 0 2009-03-31 16:17 file_owned_by_root
> pep@montblanc:/tmp/test$ id
> uid=1000(pep) gid=1000(pep)
> pep@montblanc:/tmp/test$ rm file_owned_by_root
> rm: remove write-protected regular empty file `file_owned_by_root'? yes
> pep@montblanc:/tmp/test$ ls -l file_owned_by_root
> ls: cannot access file_owned_by_root: No such file or directory
> I replicate consistently the same operations in several PCs. Doesn't
> matter if the file is empty or has any data. So, I am wrong to expect that
> rm returns an error when the user doesn't have write rights over that
> file?
> josep.

No write access on file means, you can not write into the file.

Deleting a file != writing into the file

So, the operation is allowed.

However, deleting a file = writing into the directory.

Because when  you delete a file, the directory is being modified,
which means writing into the directory (in UNIX and Linux, directory
and everything else is after all files).

So, if you remove the write permission from the directory, then you
would not be able to delete a file from it.

Reply to: