slava-vishnyakov/ssh-connection

此包已被废弃,不再维护。未建议替代包。

PHP SSH 连接

0.0.4 2018-12-21 08:51 UTC

This package is auto-updated.

Last update: 2020-01-21 11:35:20 UTC


README

composer require slava-vishnyakov/ssh-connection

使用

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');

测试

vagrant up
phpunit

待办事项

  • 在 run / sudoRun 中测试转义