degagne/libssh2

PHP SSH2 包装库

v1.2.0 2018-01-24 18:57 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:48:24 UTC


README

Latest Stable Version Latest Unstable Version License composer.lock Scrutinizer Code Quality Build Status Code Intelligence Status

LibSSH2 实现了 libssh2 扩展中所有支持的 SSH2 函数。

要求

  • PHP >= 5.4
  • libssh2 扩展

安装

将 libssh2 包添加到您的 composer.json 文件中。

{
    "require": {
        "degagne/libssh2": "~1.2.1"
    }
}

或者运行 composer require degagne/libssh2

使用方法

$configuration = (new Configuration())
    ->set_username('username')
    ->set_password('password')
    ->set_host('hostname');

$authentication = new Password($configuration);

$ssh = new SSH($configuration, $authentication);
$ssh->exec('ls -ltr');

$output = $ssh->get_output();     // stdout
$errors = $ssh->get_error();      // stderr
$retval = $ssh->get_exitstatus(); // return code

使用 Kerberos

$kerberos = new Kerberos($configuration, $authentication);
$krb_cache = $kerberos->kcreate('principle');

$ssh->exec("export KRBCCNAME={$krb_cache};ls -ltr");

Kerberos 需要设置 KRBCCNAME 环境变量。