简体   繁体   English

将数据写入具有777权限的文件

[英]Writing data to a file with 777 permission

I have a .TXT file in a web-server with the permission as 777. So what are the changes that others might be able to edit the content of this file? 我在Web服务器中有一个.TXT文件,许可权为777。那么其他人可能可以编辑此文件的内容有哪些更改? The content is not much - just a number. 内容不多-只是一个数字。 Someone seems to have been tinkering with this file as the number vanished the other day! 前几天这个数字消失了,似乎有人在修改这个文件!

No one else except me has the FTP password. 除了我,没有其他人拥有FTP密码。 So I was wondering if it's the permission that's giving it away? 所以我想知道是否是被授予的许可? I'm a client side script programmer and don't have much knowledge about Linux and permissions. 我是客户端脚本程序员,对Linux和权限没有太多的了解。

If it's 777, that means anyone with an account on the system, or any application running on the system (including PHP scripts, even those owned by those other than you) can modify the file in any way. 如果是777,则意味着任何在系统上具有帐户的人,或者系统上运行的任何应用程序(包括PHP脚本,甚至包括那些非您所拥有的脚本)都可以以任何方式修改文件。

So, yes, it's possible someone tinkered with the file. 因此,是的,可能有人修改了该文件。 Could it perhaps have been a bug in your PHP script that removed the number? 可能是您的PHP脚本中的一个错误删除了该数字?

If you can do so, it would be best to reduce the permissions to something more restrictive, like 644. This will still work if the PHP script that accesses the file is executed as the same user that owns the file. 如果可以的话,最好将权限减少到更严格的限制,例如644。如果访问文件的PHP脚本是作为拥有文件的同一用户执行的,则该命令仍然有效。 Many webhosts are configured this way, so you might be able to do this. 许多Web主机都是以这种方式配置的,因此您可以执行此操作。 644 means the owner of the file can read and write to it, while others can only read. 644表示文件的所有者可以读取和写入文件,而其他人只能读取。

It's the last 7 that is the problem. 这是最后7个问题。 That 3rd 7 means read/write/execute permission for any user on the system. 3rd 7表示系统上任何用户的读/写/执行权限。 For many hosting providers, 640 or 660 is sufficiently secure for files you need to write. 对于许多托管服务提供商,640或660对于您需要写入的文件来说足够安全。

Anybody can write anything in the file, and the file can be executed by anyone. 任何人都可以在文件中写入任何内容,并且任何人都可以执行该文件。 If you never intend it to be a script, use 666 permission (or more restrictive); 如果您从不打算将其用作脚本,请使用666权限(或更严格); if do intend it to be a script, don't allow anyone to modify it (755). 如果确实打算将其用作脚本,则不允许任何人对其进行修改(755)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM