简体   繁体   English

PHP:以shell身份运行shell_exec或system?

[英]PHP: run shell_exec or system as sudo?

I have a few commands I need to invoke from my PHP web application that can only run as sudo . 我需要从只能以sudo运行的PHP Web应用程序中调用一些命令。

http://php.net/manual/en/function.shell-exec.php says (in the comments) that I can do the following: http://php.net/manual/zh-CN/function.shell-exec.php说(在注释中)我可以执行以下操作:

system('echo <password> | sudo -u root -S <command>');

It doesn't work. 没用 I'm trying to do a groupadd , useradd , etc. Suggestions? 我正在尝试进行groupadduseradd等。

Presumably that would only work if the user php runs as (apache, nobody or something else, depending on the apache config) has sudo enabled without password for that command. 大概只有在用户php运行时(apache,nobody或其他东西,取决于apache配置)才启用sudo且该命令没有密码的情况下才有效。 Which is rather unlikely, given the wide, yawning security hole it would open. 考虑到它将打开一个巨大的,打呵欠的安全漏洞,这不太可能。

To add a user to the sudo list and have it not prompt for a password for a certain program... edit your /etc/sudoers file as such: 要将用户添加到sudo列表中,并且不提示您输入某个程序的密码,请按照以下步骤编辑/ etc / sudoers文件:

Cmnd_Alias BUNDLE = /usr/bin/bundle

deploy  ALL=(ALL) NOPASSWD:BUNDLE

Where deploy is the username and /usr/bin/bundle is the path the program that I want to access without password. 其中deploy是用户名,/ usr / bin / bundle是我要访问的没有密码的程序的路径。

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

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