doulieyu0881 2011-03-13 23:07
浏览 215
已采纳

PHP:运行shell_exec或系统作为sudo?

I have a few commands I need to invoke from my PHP web application that can only run as sudo.

http://php.net/manual/en/function.shell-exec.php says (in the comments) that I can do the following:

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

It doesn't work. I'm trying to do a groupadd, useradd, etc. Suggestions?

  • 写回答

2条回答 默认 最新

  • douquan2023 2011-03-13 23:16
    关注

    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:

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,