Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Apache is complaining about not being able to access a file. Is there an easy way to find out what is blocking the access?

I know that I can go through the process of knowing which groups the user belongs to, checking permissions by doing an ls -ld on every folder in the path to the file, and a final ls -l on the file itself, but that's pretty tedious. Then there's also selinux and file ACLs that could also be in play.

I also know that I can change apache's login shell from /sbin/nologin to /bin/bash, then su - apache and cd through the folders until I can't, but that is also tedious.

It's something that I do often and I suspect others do as well, so I assume there's something I'm missing that makes this easier.

share|improve this question
add comment

1 Answer

My mistake. I would like to think the following will be more helpful.

#!/bin/bash

uid=`id -u`

echo $uid

cmd='find . ! \( -user '${uid}

echo $cmd

for gid in `id -G`
do
    cmd=${cmd}' -o -gid '${gid}
done

cmd=$cmd' \)'

echo "..."
echo $cmd

for file in `find . ! \( -gid 1000 \)`
do
    a=$((`stat ${file} --print=%a`%10))

    if [ $a -eq 0 ] ; then
        echo $file
    fi
done
share|improve this answer
    
That finds files owned by the user in question. I want to know whether the user in question has read access to a file. They could have read access even if the file isn't owned by them by being a member of a group with read access, or alternatively they could be denied access because they don't have access to the folder that the file is in. –  Greg Feb 24 '13 at 2:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.