[英]Permission denied when I try to get file contents from my home folder
I run a cron job with a system user called system_user
and I make the cron job save its output to the file outputFile.txt
in my system_user's home folder /home/system_user/outputDir/outputFile.txt
. 我使用名为
system_user
的系统用户运行cron作业,并将cron作业保存到system_user的主文件夹/home/system_user/outputDir/outputFile.txt
的文件outputFile.txt
。
This all works, but now I need to access this file within my php script which is located in /var/www/html/scripts/phpScriptFile.php
and I'm getting a permission denied error. 这一切都有效,但现在我需要在我的php脚本中访问这个文件,该脚本位于
/var/www/html/scripts/phpScriptFile.php
,我收到了一个权限被拒绝错误。
I found out that the php scripts are run with apache
user, so I did this: 我发现php脚本是用
apache
用户运行的,所以我这样做了:
sudo chown system_user:apache outputFile.txt
But this did not help. 但这没有帮助。
If the cron outputs the file in let's say /var/www/html/scripts/
folder then I do not get this permission error. 如果cron在
/var/www/html/scripts/
文件夹中输出文件,那么我不会收到此权限错误。
The reason I tried to move my outputFile.txt out of the /var/www/html folder is that if I leave it then it's possible to access it via http protocol and I don't want anyone seing the content of this file. 我试图将我的outputFile.txt移出/ var / www / html文件夹的原因是,如果我离开它,那么可以通过http协议访问它,我不希望任何人查看该文件的内容。
Please advise. 请指教。
What are the permissions on outputFile.txt? outputFile.txt的权限是什么?
sudo chown system_user:apache outputFile.txt
That leaves system_user as the owner, but changes the group to apache. 这使system_user成为所有者,但将组更改为apache。 For that to work the file must be at least
rw-r-----
which could be accomplished by chmod 640 outputFile.txt
. 要使其工作,文件必须至少为
rw-r-----
这可以通过chmod 640 outputFile.txt
来完成。
Probably some rights are not correct in the folder containing the file. 在包含该文件的文件夹中,某些权限可能不正确。
Also, maybe the group for apache user is not named apache
or the group rights are not correctly assigned. 此外,可能apache用户的组未命名为
apache
或组权限未正确分配。
Reassign your user group: 重新分配您的用户组:
sudo chown system_user:system_user outputFile.txt
And test giving general read permissions to the whole path: 并测试给整个路径的一般读取权限:
chmod o+rx /home/system_user
chmod o+rx /home/system_user/outputDir
chmod o+r /home/system_user/outputDir/outputFile.txt
If this works (should do), then you can try to investigate if the group name was correct move the access rights to the group part. 如果这样做(应该这样做),那么您可以尝试调查组名是否正确移动对组部件的访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.