Esegui i comandi SSH tramite PHP dal server A al server B.
Ecco come eseguire i comandi ssh con la riga di comando in Linux:http://www.youtube.com/watch?NR=1&feature=fvwp&v=YLqqdQZHzsU
Per eseguire comandi su Linux con PHP usa il comando exec().
Spero che questo ti faccia iniziare a guardare nella giusta direzione.
Guarda questi due post per automatizzare la richiesta della password
- https://serverfault.com/questions/241588/how-to-automate-ssh-login-with-password
- https://serverfault.com/questions/187036/execute-ssh-command-without-password
Ecco un rapido esempio con non funzionante codice per farti pensare:
<?php
$server = "serverB.example.org";
//ip address will work too i.e. 192.168.254.254 just make sure this is your public ip address not private as is the example
//specify your username
$username = "root";
//select port to use for SSH
$port = "22";
//command that will be run on server B
$command = "uptime";
//form full command with ssh and command, you will need to use links above for auto authentication help
$cmd_string = "ssh -p ".$port." ".$username."@".$server." ".$command;
//this will run the above command on server A (localhost of the php file)
exec($cmd_string, $output);
//return the output to the browser
//This will output the uptime for server B on page on server A
echo '<pre>';
print_r($output);
echo '</pre>';
?>
Il flusso consigliato è eseguire un comando sul server A su SSH al server B
Usa phpseclib per inviare in modo sicuro SSH o SCP a server remoti
Installa concomposer require phpseclib/phpseclib
use phpseclib\Crypt\RSA;
use phpseclib\Net\SSH2;
use phpseclib\Net\SCP;
// Load your private key
$key = new RSA();
$key->loadKey('private key string');
// Connect to the server
$ssh = new SSH2('ip_address', 'port', 'timeout');
if (!$ssh->login('username', $key)) {
throw new Exception("Unable to connect");
}
// Run a remote command
echo $ssh->exec('whoami');
// SCP put a string
$result = (new SCP($ssh))->put('remotePath', 'content to put');
// SCP put a file
$result = (new SCP($ssh))->put('remotePath', 'localPath', SCP::SOURCE_LOCAL_FILE);
// SCP get a file
$result = (new SCP($this->ssh))->get('remotePath', 'localPath');
// $result is true or false