Linux – Why I can’t access to this directory after that I use the chown command

chownfile-permissionslinuxpermissionsUbuntu

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:

  1. 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.

  2. 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 negato

The 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

Best Answer

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/www

It's possible that you may not need sudo: you can certainly first try it without.

Related Question