2015-08-13 18:13
浏览 187


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


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

When that failed, as a test I ran:


I have run a shell_exec without the sudo command:


echo $list;

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


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


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}
    打赏 评论

相关推荐 更多相似问题