大网数据广告活动
服务器运维问答

"stat" says "permission denied", even though all the permissions are in place

· 52CE 我爱测

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 '/ho…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。