1

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...

1 Answer 1

1

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');
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.