2

There's something strange on the Raspbian linux about file permissions: Logging in with the default pi user end executing

sudo touch new_file

and then

ls -l new_file

yields

-rw-r--r-- 1 root root 0 May 28 09:33 new_file

but then,without sudo I can delete the file with

rm new_file

Even if it prompts the following

rm: remove write-protected regular empty file 'new_file'? y

Pressing y the file is deleted.How is that possible?

2
  • by default user pi is given many root privilege which enables user to do sudo tasks without explicitly adding sudo May 28 '18 at 9:59
  • The term here would then be capabilities(7) or group memberships. May 28 '18 at 10:39
1

The reason you can delete the file new_file despite not being its owner, is because you have write permissions to the directory that holds new_file (this directory is probably pi's home directory.)

You can check this with stat .

It's also worth mentioning that if the directory has the sticky bit enabled (for example, /tmp), then having write permissions in the directory isn't sufficient to allow you to delete contained files.

1
  • 1
    Note you are not deleting the file, you are removing (rm), the entry from the directory (you have write permission on this directory). If there are no references left to the file (no directory entries, and no processes have the file open), then the OS will garbage collect it: delete it (Unix uses a reference counting garbage collector). May 28 '18 at 11:03
0

You can remove the file because the user pi has all permissions in his home directory /home/pi. If you create another file under another directory that doesn't belong to the user pi, for example

cd /
touch file

you can't rm it.

4
  • so why can't I touch anything in directories that are upper than the home directory in the filesystem tree without sudo? May 28 '18 at 10:13
  • Ok,that's because the folder permissions May 28 '18 at 10:15
  • My response was incorrect, I edited it.
    – Dababi
    May 28 '18 at 10:22
  • @AntonioDelSannio do you mean below (not above). I know every one seems to draw trees upside down. With the root in the air, but they are wrong. The root is at (in) the ground. May 28 '18 at 11:08

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.