Q:

How to set permissions to use 'ls'

I have a folder (which is owned by another user but the same group) and I want to view it's contents, but I always get the following error message:
"ls: cannot open directory .: Permission denied"

But the group has rwx-permissions!
Eg:

folder /var/log/somefolder is owned by www-data:www-data
user user1 belongs to group www-data (but this is not the main-group).

Which permissions do I have to set, that user1 is allowed to view the folders contents and write to it?

A:

The execute permission should be enough to list the directory content. But you have to make sure that all directories in the parent tree have execute permission as well, otherwise user1 can't traverse the tree down to this directory that you want to ls.
For example if you want to check the content of /var/www but you have no permissions on the directory /var, then you can't do ls /var/www because you can't walk the tree from / down to /var/www.
Another problem might be if SELinux is enabled. Is it enabled?

A:

Edit
Obviously, you need to use newgrp www-data to make this supplementary group be your primary group. After this, you can ls that directory in question.
For me, it works without the newgrp:
$ ls -l
drwxr-x--- 2 root     adm          4096 Aug 19 14:26 ls-test
$ id
uid=1000(ott) gid=1000(ott) groups=1000(ott),4(adm),5000(vmail)
$ ls -l ls-test/
total 0
-rw-r--r-- 1 root root 0 Aug 19 14:26 xxx

What's your distribution, what version?

