Reputation: 9
Shell_exec works correctly in PHP, but when using ssh it does not return any output..
<?php
echo shell_exec("/usr/bin/ssh -i /tmp/key server 'ls'");
?>
The above command works fine in a bash shell and the following displays the proper output in PHP
<?php
echo shell_exec("ls");
?>
I was hoping this could be done without using a third party php library...
Upvotes: 1
Views: 2124
Reputation: 16792
Using phpseclib, a pure PHP SSH2 implementation:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('/tmp/key'));
if (!$ssh->login('username', $key)) {
exit('Login Failed');
}
echo $ssh->exec('ls');
?>
Upvotes: 1