dongxizhe9755 2015-08-13 18:13
浏览 220
已采纳

sudo:没有tty存在且没有指定askpass程序使用shell_exec时

I have a php page that is trying to run a service restart using:

$list=shell_exec('sudo /sbin/service NetworkManager restart');

I needed to edit my sudoers file to let this happen. Thus:

#Defaults requiretty

and

apache ALL=(ALL) NOPASSWD: /sbin/service

When that failed, as a test I ran:

apache ALL=(ALL) NOPASSWD: ALL

I have run a shell_exec without the sudo command:

$list=shell_exec('whoami');

echo $list;

This returned "apache" as expected. So I ran:

$list=shell_exec('id');

echo $list;

This returned “uid=48(apache) gid=48(apache) groups=48(apache),10(wheel)”

I checked the permissions of the files against a working system that is doing the same thing and they matched up. After that just for testing sake I changed all file permissions to 777. Still nothing. In the apache error log I get the line "sudo: no tty present and no askpass program specified". As I understand it that applies to the #Defaults requiretty line in the sudoers file but as stated that has been commented out. I have done a bit more testing with it and my current entry in the sudoers file is:

#Defaults requiretty

ALL ALL=(ALL) NOPASSWD: ALL

I know not to run the server this way as it is a huge security risk but at this point I am at a total loss for what is locking me down. Selinux is off all permissions are 777 and the ownership of files matches a working system I have. With all of this and all possible security I can think of turned off I still have the “sudo: no tty present and no askpass program specified” line in my /var/log/httpd/error_log every time. The output of:

$list=shell_exec('sudo echo "yes" 2>&1 ');

echo $list;

Is also “sudo: no tty present and no askpass program specified”? I could really use some help on this one. I have read every article for 4 google pages on this every way I can think to google it.

  • 写回答

1条回答 默认 最新

  • doufu4333 2015-08-14 10:13
    关注

    Although my setup is a little different (I'm not trying to achieve it without a password), I use this in the sudoers file:

    apache ALL=(ALL) ALL
    Defaults:apache !requiretty
    

    I then run things as:

    echo '{password}' | sudo -S {command}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题