我有一些命令需要从我的PHP web应用程序调用,它只能运行为sudo
。PHP:运行shell_exec或系统为sudo?
http://php.net/manual/en/function.shell-exec.php说(在评论),我可以做到以下几点:
system('echo <password> | sudo -u root -S <command>');
它不工作。我正在尝试做一个groupadd
,useradd
等建议?
我有一些命令需要从我的PHP web应用程序调用,它只能运行为sudo
。PHP:运行shell_exec或系统为sudo?
http://php.net/manual/en/function.shell-exec.php说(在评论),我可以做到以下几点:
system('echo <password> | sudo -u root -S <command>');
它不工作。我正在尝试做一个groupadd
,useradd
等建议?
将用户添加到列表须藤,让它不提示输入密码一定程序...编辑/ etc/sudoers文件这样:
Cmnd_Alias BUNDLE = /usr/bin/bundle
deploy ALL=(ALL) NOPASSWD:BUNDLE
如果部署是用户名,/usr/bin/bundle是我想要在没有密码的情况下访问的程序的路径。
大概只有当用户php运行为(apache,没有人或别的东西,取决于apache配置)才能工作,sudo启用时没有该命令的密码。考虑到它打开的宽阔的打哈欠安全漏洞,这是不太可能的。
我会试试看。看看这个:http://shayanth.blogspot.com/2009/05/how-to-execute-sudo-shell-command-in.html。它建议使用'$ outPut = shell_exec(“echo password_for_the_user | sudo -S command_to_execute”);' - 也不适合我。任何想法为什么? – StackOverflowNewbie 2011-03-13 23:33:35