Why I can't access to this directory after that I use the chown command?
Olivia Zamora
I am not so into Linux and I have the following problem.
I have installed a LAMP environment of an Ubuntu Linux system dedicated to the develop (it is on my PC and it is not a production server).
So I am trying to set the /var/www as the workspace of Aptana (the IDE that I use for PHP develop) but I can't do it because I have not the permission to write in this directory (I think that it is my logged user that have not this permission).
So I done:
sudo chown -R andrea:www-data /var/www/
sudo chmod -R g+s /var/www/So:
First I set my user (named andrea) as the owner of the /var/www/ directory (so I that it means that it can write into this directory) and assigns the www-data group.
Then I set this directory with g+s makes all new files created in said directory have their group set to the directory's group.
The problem is that when now I try to access to this /var/www/ directory I obtain a permission denied error message, something like this:
andrea@andrea-virtual-machine:/var$ cd www/
andrea@andrea-virtual-machine:/var/www$ ls
ls: impossibile aprire la directory .: Permesso negatoThe text is in italian and means: impossible to open the directory: access denied
Why? What am I missing? How can I solve this issue?
EDIT-1: This is the output of the sudo ls -al /var/www command:
andrea@andrea-virtual-machine:/var/www$ sudo ls -al /var/www
[sudo] password for andrea:
totale 16
d-wx--s--x 4 andrea www-data 4096 apr 27 15:19 .
drwxr-xr-x 14 root root 4096 apr 27 11:53 ..
drwxr-sr-x 2 andrea www-data 4096 apr 27 12:08 html
drwxrwsr-x 3 andrea www-data 4096 apr 27 15:20 .metadata 3 3 Answers
If you have execute without read permission on a directory, you can include it in a path, but you cannot see its contents, so if you are in /var/www you can for instance see the contents of the html subdirectory with ls html, even though you cannot see html with a simple ls. You need to run:
sudo chmod uga+r /var/wwwIt's possible that you may not need sudo: you can certainly first try it without.
It's not an Ubuntu difference, it's how Linux permissions work. Execute (x) permission is to access the directory, Read (r) permission is to list its content.
From this article on Wikipedia, that I recommend you to read all:
When set for a directory, this permission [executes] grants the ability to access file contents and meta-information if its name is known, but not list files inside the directory, unless read is set also.
also
When set for a directory, this permission [read] grants the ability to read the names of files in the directory, but not to find out any further information about them such as contents, file type, size, ownership, permissions.
andrea@andrea-virtual-machine:/var/www$ sudo ls -al /var/www
d-wx--s--x 4 andrea www-data 4096 apr 27 15:19 .For user andrea:
(w) Write rights
(x) allowed to cd to the folder.
No (r) was set on the current folder, so you are not allowed to list its contents. This is why ls will fail.
The same rights are set on the group and on other (no r either)