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?
Best Answer
This is a permissions problem, not an ownership problem.
Execute permissions (abbreviated
x
and appearing where the-
is inrw-
) 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 asroot
will try to respect permissions in order to abide by the wishes of the user. Butroot
has the power to perform any operation (that the OS is capable of performing) on any file or directory. In aroot
shell,cd
ing into a directory that doesn't have any execute permissions will succeed.The solution to the problem is to run:
That gives (
+
) the owner ofmasternotes
(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:
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 asroot
--it is deliberate that I have not includedsudo
in either command. You own the folder, so you can change its permissions yourself--you don't needroot
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):
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: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.