Unable to run SSH through php on XAMPP in Linux

I'm trying to run SSH in python through os.system() which is being invoked by PHP. It works fine when I run it through the CLI version of PHP but it is not running through lamp.

Following is my php code:

<?php $x=shell_exec('python test.py'); ?>

and below is the python code (test.py) which is being invoked by the PHP code:

import os
os.system("ssh [email protected]")

I also tried using touch utility through exec() in PHP, the same thing happens.

Upvotes: 1

Views: 326

Answers (1)

natsprtacare
natsprtacare

Reputation: 11

Use phpseclib. Using the ssh2 extension as recommended by @Ramesh Dahiya is bad for a number of reasons as elaborated here:

http://phpseclib.sourceforge.net/ssh/compare.html

Example of phpseclib being used:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>

Upvotes: 1

Related Questions