luka/php-ssh 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

luka/php-ssh

Composer 安装命令:

composer require luka/php-ssh

包简介

Provides an object-oriented wrapper for the php ssh2 extension.

关键字:

README 文档

README

Build Status (develop)

Provides an object-oriented wrapper for the php ssh2 extension. This is based on the work of Antoine Hérault.

Requirements

You need PHP version 7.1+ with the SSH2 extension.

Installation

The best way to add the library to your project is using composer.

$ composer require luka/php-ssh:^2.0

Usage

Configuration of the connection

To establish an SSH connection, you must first define its configuration. For that, create a Configuration instance with all the needed parameters.

<?php

// simple configuration to connect "my-host"
$configuration = new Ssh\HostConfiguration('my-host');

The available configuration classes are:

  • Ssh\HostConfiguration
  • Ssh\OpenSSH\ConfigFile

Both connection configuration and public/private key authentication can be obtained from a ssh config file such as ~/.ssh/config

<?php

// simple configuration to connect "my-host"
$configuration = Ssh\OpenSSH\ConfigFile::fromHostname('my-host', '~/.ssh/config');
$authentication = $configuration->createAuthenticationMethod('optional_passphrase', 'optional_username');

Create a session

The session is the central access point to the SSH functionality provided by the library.

<?php
// ... the configuration creation
$session = new Ssh\Session($configuration);

Authentication

The authentication classes allow you to authenticate over a SSH session. When you define an authentication for a session, it will authenticate on connection.

<?php

$configuration = new Ssh\HostConfiguration('myhost');
$authentication = new Ssh\Authentication\Password('John', 's3cr3t');

$session = new Session($configuration, $authentication);

The available authentication are:

  • None for username based authentication
  • Password for password authentication
  • PublicKeyFile to authenticate using a public key
  • HostBasedFile to authenticate using a public hostkey
  • Agent to authenticate using an ssh-agent

Authentication from Ssh\OpenSSH\ConfigFile

If you use an ssh config file you can load your authentication and configuration from it as follows:

<?php

$configuration = Ssh\OpenSSH\ConfigFile::fromHostname('my-host');
$session = new Ssh\Session($configuration, $configuration->createAuthenticationMethod());

This will pick up the username, and your public and private keys from your config file Host and Identity declarations.

This simple snippet only works if the User declaration is also present, and the private key does not require a pass phrase. If any of this is not the case you have to pass the missing values to the createAuthentication() method.

Subsystems

Once you are authenticated over a SSH session, you can use the subsystems.

Sftp

You can easily access the sftp subsystem of a session using the getSftp() method:

<?php

// the session creation
$sftp = $session->getSftp();

See the Ssh\Sftp class for more details on the available methods.

Publickey

The session also provides the getPublickey() method to access the publickey subsystem:

<?php

// ... the session creation
$publickey = $session->getPublickey();

The Public-Key subsystem allows you to provide multiple public keys to use for authentication. See the Ssh\Publickey class for more details on the available methods.

Exec

The session provides the getExec() method to access the exec subsystem

<?php

// ... the session creation

/** @var Ssh\Session $session */
$exec = $session->getExec();
echo $exec->run('ls -lah')->getExitCode(), PHP_EOL;

See the Ssh\Exec class for more details.

luka/php-ssh 适用场景与选型建议

luka/php-ssh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 126 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ssh」 「ssh2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 luka/php-ssh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 luka/php-ssh 我们能提供哪些服务?
定制开发 / 二次开发

基于 luka/php-ssh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 126
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 78
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-11