问题原文
原帖链接 · Pappani · CC BY-SA 4.0
I have this:
ls -al /home/my_user/dir1/dir2/file1.txt
-rwxr-xr-x 1 http http 2798 Dec 30 18:18 /home/my_user/dir1/dir2/file1.txt
However, I can't stat it:
sudo -u http stat /home/my_user/dir1/dir2/file1.txt
stat: cannot stat '/home/my_user/dir1/dir2/file1.txt': Permission denied
Why? How to fix that without having to chmod 777 <path>, is there more approprivate way
?
社区高分解答
原帖链接 · Manuel Florian · CC BY-SA 4.0
I think you need to verify the permissions of each folder involved in the path before you get to the file itself.
Many Linux distributions default the permissions to (0700) (meaning just the user itself is allow to read/write/execute), to each folder inside the /home directory, which means that if user my_user has a file /home/my_user/dir1/dir2/file1.txt with the permissions 0755 the user http can't stat it because the default permissions I mentioned above will prevent it.
My guess is that when you executed the ls -al /home/my_user/dir1/dir2/file1.txt was with a user other than http and that user could actually read the file. If that is the case, you have to correct the permissions on all the directories with tools like chmod or setfacl if you want to be more specific.
I hope this helps.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
