PHP code example of slava-vishnyakov / ssh-connection

1. Go to this page and download the library: Download slava-vishnyakov/ssh-connection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

slava-vishnyakov / ssh-connection example snippets


use SlavaVishnyakov\SshConnection\SshConnection;

$ssh = new SshConnection($username, '127.0.0.1:2222');
$ssh->privateKeyPath = 'my_private_key';
// $ssh->privateKeyPassword = '';
// $ssh->useAgent = true;

$ssh->connectAndReadMotd();

$result = $ssh->run('echo Hello');
print($result->stdout); // "Hello"
print($result->stderr); // ""
print($result->exitCode); // 0

$ssh->sudoPassword = 'vagrant';
$result = $ssh->sudoRun('whoami');