Shell_exec throws: sudo: no tty is present and the requested program is not specified

I am trying to execute a script using shell_exec () function in php:

I wrote the following lines of code:

$command = "bash /path/to/my/script/ funciton_name() 2>&1";
echo shell_exec($command);

      

Inside a shell script, I do:

sudo rsync -avvc /source/path /destination/path

      

When doing this in a browser, I get the following error message:

sudo: no tty present and no askpass program specified

      

When I execute the same shell script on my server, it runs fine.

When I looked at similar questions posted on this forum, I realized that I had to add the NOPASSWD line on my server, which I found out about is already added in the following format:

User_Alias  NOBODY=nobody,apache
NOBODY  ALL=(ALL) NOPASSWD : /path/to/my/script

      

Also when I do:

echo shell_exec("whois");

      

I am getting output as:

apache

      

Any help to overcome this issue would be greatly appreciated.

+3


source to share


1 answer


sudo

a TTY will be required even if you set it up without a password, unless explicitly requires one . But as @Cfreak pointed out , it would be much better (easier and safer ) to avoid sudo

setting the correct permissions (read it first before continuing).



rsync

by itself will not require root privileges to configure * nix securely. To test this, you can check that it type -a rsync

doesn't print anything strange like rsync is aliased to `sudo rsync'

, and that it ls -l $(which rsync)

prints reasonable resolutions (at least rx

for everyone).

0


source







All Articles