如何从PHP调用需要SUDO shell脚本? [英] How to call shell script from php that requires SUDO?

查看:118
本文介绍了如何从PHP调用需要SUDO shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件就是一个bash脚本,需要sudo来工作。

I have a file that is a bash script that requires SUDO to work.

我可以在命令行中使用sudo运行它,但我会提示放入SUDO密码。

I can run it from the command line using SUDO but I will be prompted to put in the SUDO password.

我想通过了shell_exec 来从PHP这个脚本,但我如果我叫SUDO,它不喜欢命令行,我可以提示输入密码。有没有办法为须藤通过密码与sudo的电话吗?

I want to run this script from php via shell_exec but I if I call SUDO, its not like a command line where I can be prompted for the password. Is there a way to pass the password for sudo with the sudo call?

我怎样才能做到这一点?

How can I do this?

推荐答案

编辑sudoers文件(使用 visudo命令),并添加一条规则,允许Web服务器用户运行没有密码的命令。例如:

Edit the sudoers file (with visudo) and add a rule that allows the web server user to run the command without a password. For example:

www-data ALL=NOPASSWD: /path/to/script

这篇关于如何从PHP调用需要SUDO shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆