bash Ubuntu 允许 www-data 写入新文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50862197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu allow www-data to write to new files
提问by Mike Kaharlykskiy
How to allow www-data group on Ubuntu to write into new just created files by www-data?
如何允许 Ubuntu 上的 www-data 组通过 www-data 写入新创建的文件?
I'm using a PHP script and it creates a file (owner is www-data), and after that I need to write to this file. But it failed, I think because www-date hasn't write access to new file.
我正在使用 PHP 脚本并创建一个文件(所有者是 www-data),然后我需要写入该文件。但它失败了,我认为是因为 www-date 没有对新文件的写访问权限。
And provide all access to all users to the directory where this file need to be created but it doesn't work because new file is created by www-data so it doesn't have permission to write.
并为所有用户提供对需要创建此文件的目录的所有访问权限,但它不起作用,因为新文件是由 www-data 创建的,因此它没有写入权限。
My script:
我的脚本:
crontab -l > file && echo \"test\" >> file
回答by Kevin Hill
You will need to make sure that the directory you are writing to allows for www-data to write to it. Typically, you will want to put that directory in a place that is away from other files etc...
您需要确保您正在写入的目录允许 www-data 写入它。通常,您希望将该目录放在远离其他文件等的地方...
sudo chown www-data:www-data <DIRNAME>
sudo chmod g+w <DIRNAME>
should do the trick for you.
应该为你做的伎俩。
If the filename you are writing to already exists, the same commands above, applied to the file itself, should work as well. Typically, if the PHP script you wrote is creating the file, and failing, it's due to the parent directory permissions. For clarity - the commands that would adjust the file permissions and ownership.
如果您要写入的文件名已经存在,则上述应用于文件本身的相同命令也应该可以正常工作。通常,如果您编写的 PHP 脚本正在创建文件,但失败了,这是由于父目录权限所致。为清楚起见 - 将调整文件权限和所有权的命令。
sudo chown www-data:www-data <FILENAME>
sudo chmod g+w <FILENAME>
Finally, should you not be able to adjust the ownership of either the directory or the file, you can assign other or all access. But I would highly recommend NOT doing this for various scary security reasons.
最后,如果您无法调整目录或文件的所有权,您可以分配其他或所有访问权限。但出于各种可怕的安全原因,我强烈建议不要这样做。