Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've read a little about chmod and have a high-level understanding of file permissions. But I'm a little confused about the concept of an 'owner'.

If my user account is the 'Owner' of a directory but it has no permissions (chmod 0000) does my user have any more ability to do anything than another random user on the system? Assuming neither user is a super user?

share|improve this question
add comment

4 Answers 4

up vote 5 down vote accepted

chmod 00000 makes the directory/file inaccesable to owner and group. The only thing you and the group that owns the file can do is remove it with rm -rf tmp/. Nothing better than an example:

$ mkdir tmp
$ chmod 00000 tmp
$ cd tmp
bash: cd: tmp: Permission denied

You can see the directory with ls -l

d--------- 2 rinzwind rinzwind   4096 Oct 13 14:35 tmp

and but only with sudo permissions can you enter the directory ...

 $ sudo su
 # cd tmp
 #

Regarding the other posts: yes you can remove a file/dir that is chmodded to 00000:

$ mkdir tmp
$ chmod 00000 tmp
$ rm -rf tmp/
$ touch 1
$ chmod 00000 1
$ rm 1
rm: remove write-protected regular empty file `1'? y
$ 

As the owner you are also allowed to reset the permissions. That is something someone else (except for root) is allowed too.

share|improve this answer
    
I was surprised by this; but I can confirm it is correct. Owners can remove directories even if they have no other rights. –  Rob P. Oct 13 '12 at 21:00
    
IIRC, removing a file has to do with the permissions of the directory containing the file, since the file itself isn't getting modified - the reference to the file in the directory is what is getting removed. I'm guessing you can also make a hardlink to that file as well. –  Izkata Oct 13 '12 at 21:01
    
@RobP. As demonstrated by the script I added to my response file ownership does not allow you to delete it. You need write access to the directory. –  BillThor Oct 13 '12 at 23:50
    
The most important part of the answer is that the owner can change permissions. You might consider putting that info at the beginning of your answer. –  Jeremy Stein Oct 16 '12 at 18:06
add comment

A directory is just a special kink of file so the following applies equally to directories and files.

Being the owner allows you to reset access to the file so that you can then read the file. Other than root, other users won't be able to do so.

Until you reset the access the file will be inaccessible to you the same as it would be for other users.

Begin the owner of the file does not allow you to remove (delete it). You must have write access to the containing file to remove it.

Example script demonstrating what can and can't be done. (Don't run as root, but requires sudo access.):

#!/bin/bash

DIR=directory$$
FILE=$DIR/file$$

echo We can remove it - own both file and directory
mkdir $DIR
date > $FILE
chmod 0000 $FILE
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo

echo We can not remove it - no write access to directory
date > $FILE
chmod 0000 $FILE
chmod -w $DIR
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo

echo We can remove it - even if we do not own it
chmod 0000 $FILE
chmod +w $DIR
sudo chown root:root $FILE
ls -ld $DIR $FILE
rm -f $FILE
ls -ld $DIR $FILE
echo

echo We can not remove it - even if we can read it - do not own directory
date > $FILE
cat $FILE
sudo chown root:root $DIR
ls -ld $DIR $FILE
cat $$FILE
rm -f $FILE
ls -ld $DIR $FILE
echo

sudo chown $LOGNAME $DIR
echo Now we can clean up
rm -f $FILE
rmdir $DIR

# EOF
share|improve this answer
    
Sorry but you can remove a dir/file that has 00000 as permissions if you are the owner. –  Rinzwind Oct 13 '12 at 18:55
    
@Rinzwind I verified before posting. Deletion is a change to the containing directory. You don't need to own or have access to the file to delete it if you can update the directory that owns it. –  BillThor Oct 13 '12 at 23:18
    
Correct but it was part of the question: the owner owns the directory and then removing is the 1 distinct difference over what anyone else can do (except for root ofc.) :) I agree with your assesment too ;) The reason for deleting being check on the directory prevents you from making irrepairable mistakes. –  Rinzwind Oct 14 '12 at 5:01
add comment

If my user account is the 'Owner' of a directory but it has no permissions (chmod 0000) does my user have any more ability to do anything than another random user on the system?

The simple answer is, No, the owner won't have any other facility for being owner of the directory when it is chmoded to 0000. Because the permission bit for owner is also 0, which means no read/write/execute permissions for him.

Check the Linux file permission bit

share|improve this answer
1  
Except that the owner/group can delete it ;) –  Rinzwind Oct 13 '12 at 18:54
add comment

Yes. As the owner, you can use chmod to give yourself whatever permissions you need.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.