简体   繁体   English

在Apache服务器上使用PHP CHMOD Linux目录

[英]CHMOD a linux directory using PHP on an apache server

Has anyone ever used PHP (proven and successful) to CHMOD a directory through a Web Browser? 有没有人曾经使用过PHP(经过验证并成功)通过Web浏览器对目录进行CHMOD?

My roadblocks are: (a) PHP script runs as "nobody" from the browser (b) directory above the one I want to CHMOD is owned by the ftp user and "nobody" does not have write permissions to it 我的障碍是:(a)浏览器中的PHP脚本以“ nobody”的身份运行(b)我要CHMOD的目录上方的目录归ftp用户所有,并且“ nobody”没有写权限

So when I try to chmod 0666 /usr/www/dirOwnedbyFTPuser/dirIamTryingToCHMOD/ I get Permission denied 因此,当我尝试使用chmod 0666 / usr / www / dirOwnedbyFTPuser / dirIamTryingToCHMOD /时,我的权限被拒绝

If you have ever written and successfully run a script to do this, can you share the snipit of code with me? 如果您曾经编写并成功运行脚本来执行此操作,那么您可以与我分享代码的提神吗? Thanks...been at this for months. 谢谢...几个月来。

Yes, you can chmod from php via a web browser. 是的,您可以通过网络浏览器从php更改chmod。 (yes we all know it can be a bad idea).. (是的,我们都知道这可能是个坏主意)。

But - you can only chmod files that the php script has permission to use! 但是-您只能chphp文件有权使用的文件! if your web server runs PHP as nobody, then you can chmod any files owned by "nobody"... 如果您的Web服务器以无人的身份运行PHP,那么您可以chmod“ nobody”拥有的任何文件...

Yes it is possible to do this via php. 是的,可以通过php做到这一点。 Usual linux permissions rules apply however so as you are looking to chmod scripts not owned by the apache user (nobody) and the apache user does not have write permissions then one method is to give apache permission to use sudo 但是,通常会使用linux权限规则,因此当您查找不属于apache用户(没人)拥有的chmod脚本,并且apache用户没有写权限时,一种方法是授予apache权限以使用sudo

Be warned - this is potentially a massive security hole!!! 警告-这可能是一个巨大的安全漏洞!!!

You can give apache permission to use sudo by editing the sudoers file. 您可以通过编辑sudoers文件来授予apache使用sudo的权限。 It is recommended that you do not edit this file directly as an error can leave you completely screwed so on my (Ubuntu) system I type 建议您不要直接编辑此文件,因为错误可能会使您完全不知所措,因此在我键入的(Ubuntu)系统上

sudo visudo

Then you need to add a line for your "nobody" user. 然后,您需要为“ nobody”用户添加一行。 You can restrict sudo permissions to a particular script or folder so i would recommend writing a shell script to change the permissions and then placing this in a folder away from any other scripts. 您可以将sudo权限限制为特定的脚本或文件夹,因此我建议编写一个shell脚本来更改权限,然后将其放置在远离任何其他脚本的文件夹中。 That way apache doesn't have complete root privileges on your system (which is a pretty scary thought). 这样,Apache在您的系统上就没有完整的root特权(这是一个非常可怕的想法)。 You can also put some code in the shell script to restrict which files can be changed. 您还可以在shell脚本中放置一些代码,以限制可以更改的文件。

You also need to allow apache to sudo without a password as you have no way of entering the password through php. 您还需要允许apache在没有密码的情况下进行sudo,因为您无法通过php输入密码。 So the line you would add is something like 所以您要添加的行类似于

nobody ALL=(ALL)NOPASSWD:/path/to/my/script

Then in php you just prefix the command with sudo 然后在php中,您只需在命令前加上sudo

passthru ("sudo /path/to/my/script ...");

(there are a few other functions you can use instead of passthru(), was just the first that came to mind) (您可以使用其他一些函数来代替passthru(),这只是我想到的第一个函数)

As I said before, this is potentially very dangerous and whilst the above will work, I have only used it on my own private system before, never on a public production server. 就像我之前说过的那样,这可能非常危险,尽管上面的方法可以工作,但我以前只在自己的私有系统上使用过它,而从未在公共生产服务器上使用过。 I'm sure plenty of people will have comments on the security of this so I would be interested to hear what other potential pitfalls and security holes there could be with this method. 我相信会有很多人对此安全性发表评论,所以我很想听听这种方法还有哪些其他潜在的陷阱和安全漏洞。 I know a similar thing can be done using SuExec but am not so familiar with it so if anyone has any pros or cons of SuExec over this method I would be interested to hear them. 我知道使用SuExec可以完成类似的操作,但并不十分熟悉,因此,如果有人对SuExec的这种方法有任何优缺点,我很想听听他们的意见。

Final note: I would change the apache user from nobody to something like 'apache' or 'www' - probably just being silly but I don't like the idea of giving root permissions to a user called nobody!!! 最后说明:我会将apache用户从没有人更改为“ apache”或“ www”之类的东西-可能只是愚蠢,但我不喜欢将root权限授予名为nobody的用户的想法!!!

Hope this helps! 希望这可以帮助!

http://www.php.net/ftp您可以让php以ftp用户身份登录并执行操作。

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

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