简体   繁体   中英

PHP shell_exec will not execute ssh

I am running PHP and Apache. My program is as follows:

<?php
echo shell_exec("ssh");
?>

It works from the command line as php script.php but when visiting the web browser 127.0.0.1/script.php it returns an empty result.

Any ideas why this may be happening?

Edit 1: I tried running ssh as the www-data user through command line. This worked fine.

Edit 2: I tried running sshpass instead of ssh (same location, same permissions) and it works but ssh does not.

kamermans的注释中提到,ssh的帮助信息是输出到stderr流的,所以试试

echo shell_exec('ssh 2>&1');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM