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

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

问题描述

我有一个文件是一个需要 SUDO 才能工作的 bash 脚本.

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 调用传递 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?

我该怎么做?

推荐答案

编辑 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

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

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