5

I have a folder with my notes about the system inside.

I am logged in as user1

cd masternotes produces:

bash: cd: mastersnotes: permission denied

whoami produces: user1

ls -l produces:

drw-rw-rw-. 2 user1 user1        4096 Mar 26 20:47 masternotes

ls -l inside the directory produces:

-rw-rw-rw-. 7 user1 user1   345 Oct  7  2006 crontab
-rw-rw-rw-. 7 user1 user1   348 Oct  7  2006 crontab~
-rw-rw-rw-. 7 user1 user1  3702 Oct  7  2006 grep_usage.txt
-rw-rw-rw-. 7 user1 user1 91868 Oct  7  2006 lvm-layout-10-14-03.tif
-rw-rw-rw-. 7 user1 user1    30 Oct  7  2006 mysql
-rw-rw-rw-. 7 user1 user1 35764 Oct  7  2006 notes

I have run chmod -R 666 masternotes on the folder.

I have run chown to root and chgrp to root and back again to user1.

root can descend and enter the folder and open the file.

user1 cannot.

Any clues as to what is going on here?

0

1 Answer 1

8

This is a permissions problem, not an ownership problem.

Execute permissions (abbreviated x and appearing where the - is in rw-) are conspicuously absent from the permissions you've shown us.

Execute permissions work very differently for directories than for regular files. For directories, execute permissions give the ability to enter the directory (that is, to cd to it, or to open it up in a file manager). They also give the ability to attempt to access files in the directory (though whether or not that will succeed also depend on other permissions, sometimes including the permissions of the files being accessed).

root is able to enter the directory because it is not really bound by permissions in the usual way. In many ways, commands and applications that are run as root will try to respect permissions in order to abide by the wishes of the user. But root has the power to perform any operation (that the OS is capable of performing) on any file or directory. In a root shell, cding into a directory that doesn't have any execute permissions will succeed.

The solution to the problem is to run:

chmod u+x masternotes

That gives (+) the owner of masternotes (u) executable permissions (x) on the directory.

Then you'll be able to enter into the directory and attempt to access files there, as a normal user.

If you want members of its group owner to be able to do this too, then you could run this instead:

chmod ug+x masternotes

But you are probably the only member of your user-specific group (which owns the folder).

The chmod command here does not need to be run as root--it is deliberate that I have not included sudo in either command. You own the folder, so you can change its permissions yourself--you don't need root to do it for you.

In case you're interested in setting execute permissions numerically, remember that for each digit you add (starting with zero):

  • 4 for read.
  • 2 for write.
  • 1 for execute.

For example, if you wanted everyone to be able to read and execute some-file but only the owner to be able to write, you'd use:

chmod 755 some-file

I recommend FilePermissions in the community documentation, for further reading on file permissions in Ubuntu, including the executable bit and its special meaning for folders.

1
  • thank you for the very informative and accurate reply. If I understand this now -- I had not realized that it was necessary to have an execute bit set on the folder containing a file I wished to read and write to. It is a text file I was trying to access. chmod ug+x masternotes resolved this.
    – msmith
    Mar 27, 2013 at 5:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .