How to debug filesystem permissions

debuggingpermissions

I get permissions errors when I have a process running as root, spawning a subprocess as www-data, which then accesses a dir which is owned by root, with a subfolder which is owned by www-data, which has a symlink to a dir which is owned by a user in the group www-data, which then has…. YOU GET THE IDEA. How the heck do I know where it fails in this impossibly complex chain? All I get is Permission Denied

Without getting bogged down in the details of this particular situation, how does one begin to debug a problem like this on unix?

I want to just say

debug_permissions.sh www-data /my/long/symlink/chain```

and I want it to go through and tell me where the terminal point is (where www-data fails to have permissions)

I know there is a tool
``` namei -l /path/```
but that isn't very helpful because it doesn't let me run as another user (or at least I don't know how)

If I run 
```sudo su www-data```
I get **This account is currently not available.**

I want to be able to  "become" www-data and "cd" around to the dirs and see where i fail to see things. But, that's not letting me do this and I don't want to create a new user just to do this.

Best Answer

Aha, this does it:

sudo -H -u www-data namei /my/long/symlink/chain

where www-data is the user I'm trying to debug

Related Question