Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过php shell_exec执行bash脚本时出现权限错误_Php_Linux_Bash_Sed_Shell Exec - Fatal编程技术网

通过php shell_exec执行bash脚本时出现权限错误

通过php shell_exec执行bash脚本时出现权限错误,php,linux,bash,sed,shell-exec,Php,Linux,Bash,Sed,Shell Exec,我试图通过bash脚本将行插入到/etc/ppp/chap secret文件中,该脚本应与php shell\u exec一起运行 我希望我走的是正确的道路,还是有更好的方法? 不管我下面的工作是什么 /var/www/test.php: <?php echo shell_exec("cd /etc/ppp; bash test.sh"); ?> 我还向sudoers添加了www-data-ALL=NOPASSWD:/etc/ppp/test.sh。 我得到这个错误: sed:无法

我试图通过
bash脚本
将行插入到
/etc/ppp/chap secret
文件中,该脚本应与
php shell\u exec
一起运行

我希望我走的是正确的道路,还是有更好的方法? 不管我下面的工作是什么

/var/www/test.php:

<?php echo shell_exec("cd /etc/ppp; bash test.sh"); ?>
我还向sudoers添加了
www-data-ALL=NOPASSWD:/etc/ppp/test.sh。

我得到这个
错误

sed:无法打开临时文件。/sedXym2Nn:权限被拒绝

从终端所有工作正常,但我需要它从管理网站通过按钮点击


如何修复权限错误并获得此过程?

授予web服务器对系统文件的访问权限似乎是鲁莽的,但至少您使用了包装器脚本来防止服务器以超级用户权限运行任意命令。也就是说:

您已授予
www-data
sudo无密码访问
/etc/ppp/test.sh
,但您没有从
shell_-exec
函数使用sudo执行命令


调用shell_exec(“cd/etc/ppp;
sudo
bash test.sh”)应该可以做到这一点。

授予您的web服务器对系统文件的写访问权限是极不明智的。
#!/bin/bash
sed -i "/IP addresses/a client123* pw123123 192.168.0.101" chap-secrets