Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a complicated file hierarchy and I don't want to check the permissions on each directory. Is there any way to find out immediately if one file is readable by a given user? (outside of logging in as that user)

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

This will only work if you have root privileges


if the user has a valid login shell

su username -c 'ls /long/dir/user/filename'

if the user has a nologin shell /sbin/nologin and similar:

su username -s /bin/sh -c 'ls /long/dir/user/filename'

To find out why a user cannot access a file (builds readable output tree with permissions):

# namei -om /home/someuserhomedir/Maildir/

f: /home/someuserhomedir/Maildir/
dr-xr-xr-x root     root      /
drwxr-xr-x root     root      home
drwx------ someuser somegroup someuserhomedir
drwx------ someuser somegroup Maildir
share|improve this answer
    
That says Permission denied on everything, even '/'. –  Oin Jan 31 '13 at 13:23
    
right, I was gonna suggest the ticks, it works now. Thanks! –  Oin Jan 31 '13 at 13:27
2  
If you want to figure out why you can't access a file use namei: sudo -u user namei -m /long/dir/user/filename –  fuero Jan 31 '13 at 14:03
    
@fuero That's a good one, didn't know namei, thanks! –  Martino Dino Jan 31 '13 at 22:07
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.