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)
Asked
Active
Viewed 2,836 times
1 Answers
12
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

Martino Dino
- 1,145
- 1
- 10
- 17
-
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
-
2If 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