LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Why I am being able to delete a root ownedfile? (https://www.linuxquestions.org/questions/linux-software-2/why-i-am-being-able-to-delete-a-root-ownedfile-4175680221/)

coltson 08-10-2020 08:43 PM

Why I am being able to delete a root ownedfile?
 
Ok, there is this file "a" that has rwx permissions for everyone, so anyone can erase it.

I use cp to create "a2". a2 is created with has similar permissions, excepted that, for some reason, it does not allow members of other groups to write it. Then I use chown to make it to belong to root.

Yet, when I return to my normal user, I can erase it. How is that possible? And how I can avoid it?

Thanks for the help.

scasey 08-10-2020 08:51 PM

How did you use cp? As root?
What are the permies of the containing directory?

berndbausch 08-10-2020 10:09 PM

The copy of a file doesn't have to have the same permissions as the original file.

As scasey alludes, to delete a file, you need write permission in the directory that contains the file. To prevent a normal user from deleting the file, remove directory write permissions.

Rather than describing your actions, it would be better to list the commands you enter and show the details of the files you create.

tshikose 08-11-2020 04:53 AM

Hi,

It is not clear what you mean by "erase" the file, and how it can be different to "delete" the file.

If "erase" the file is emptying its content, then you need write permission to the file.
Remark that the file will still exist after being "erased", but with an empty content.

But differently, you need write permission to the containing folder to be able to "delete" the file.
That had been hinted by scasey in post #2.

ondoho 08-11-2020 11:50 AM

Quote:

Originally Posted by coltson (Post 6154575)
Ok, there is this file "a" that has rwx permissions for everyone, so anyone can erase it.

I use cp to create "a2". a2 is created with has similar permissions, excepted that, for some reason, it does not allow members of other groups to write it. Then I use chown to make it to belong to root.

Yet, when I return to my normal user, I can erase it. How is that possible? And how I can avoid it?

Show us.
Use --verbose switches where possible, and output of 'ls -al'.


All times are GMT -5. The time now is 02:00 PM.