Delete files owned by root, without being root
Unix permits non-root users to delete files that they do not own including files owned by the super-user, aka root. You can create a file, change its ownership to root and delete it.
$ touch foo $ chmod 600 foo # make the file only read-writable by owner$ sudo chown root:0 foo # change ownership of file to root$ ls -l foo-rw------- 1 root root 0 2011-01-24 12:18 foo$ rm foo$ ls -l foo ls: cannot access foo: No such file or directoryObviously there’s a catch, you can only delete files in directories that you have write access to. In fact, write permission to the parent directory, and only write permission to parent directory, controls which files you may or may not delete. So, you can also create a file, remove write permissions to the parent directory, and you will be unable to delete the file you created and still own.
$ mkdir test $ touch test/foo $ chmod -w test $ rm test/foo rm: test/foo: Permission deniedBlame inodes
Metadata for a Unix file is stored in the file inode. The inode contains useful info such as ownership information, access timestamps and pointers to the actual disk blocks that contain the file contents. What the inode does not contain is information about file name or parent directory.
Only Directories map file names to inodes. And multiple files can map to the same inode at that (you can create such hard-links using the
lncommand). Runningrmsimply removes one such reference from a single directory, so it only requires write-access to the directory in question. The disk blocks for the inode will only be reclaimed when the last reference to it is removed.
Start removing dem references!
--------------------------------------------------------------------------------
-
chvnx likes this
-
akhilravidas likes this
-
egelor likes this
-
hackedy likes this
-
chmod755 reblogged this from paksoy and added:
Start removing dem references!
-
paksoy posted this
--------------------------------------------------------------------------------