Why I can't access to this directory after that I use the chown command?

8,135

Solution 1

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.

Solution 2

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.

Solution 3

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)

Share:
8,135

Related videos on Youtube

AndreaNobili
Author by

AndreaNobili

Updated on September 18, 2022

Comments

  • AndreaNobili
    AndreaNobili over 1 year

    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
    
    • Frank Thomas
      Frank Thomas about 9 years
      please post the output of sudo ls -al /var/www
    • AndreaNobili
      AndreaNobili about 9 years
      @FrankThomas I have edited my original post putting the required information at the end of it
    • Francisco  Tapia
      Francisco Tapia about 9 years
      add read permisions
  • ganesh
    ganesh about 9 years
    Execute is effective. Without it the OP could not do things like cd /var/www/html (passing thought /var and /war/www, which need to have 'x' set for that.). It just has nothing to do with (r)eading the directories content.
  • AndreaNobili
    AndreaNobili about 9 years
    I have do as you say and it seems to work...but why? What exactly does this command? and why I have to use it? Tnx
  • AFH
    AFH about 9 years
    @Hennes - It certainly doesn't work on binaries and scripts. I thought I had also found that it failed on directories with execute and no read, but I just tested it and you are quite correct.
  • AFH
    AFH about 9 years
    @AndreaNobili - I have clarified my answer after reading Hennes' comment and answer.
  • ganesh
    ganesh about 9 years
    True. It behaves differently on files and on folders.