herzult/php-ssh
Composer 安装命令:
composer require herzult/php-ssh
包简介
Provides an object-oriented wrapper for the php ssh2 extension.
README 文档
README
Provides an object-oriented wrapper for the php ssh2 extension.
Requirements
You need PHP version 5.3+ with the SSH2 extension.
Installation
The best way to add the library to your project is using composer.
$ composer require herzult/php-ssh:~1.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\Configuration('my-host');
The available configuration classes are:
ConfigurationSshConfigFileConfiguration
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 = new Ssh\SshConfigFileConfiguration('/Users/username/.ssh/config', 'my-host'); $authentication = $configuration->getAuthentication('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\Configuration('myhost'); $authentication = new Ssh\Authentication\Password('John', 's3cr3t'); $session = new Session($configuration, $authentication);
The available authentication are:
Nonefor username based authenticationPasswordfor password authenticationPublicKeyFileto authenticate using a public keyHostBasedFileto authenticate using a public hostkeyAgentto authenticate using an ssh-agent
Authentication from SshConfigFileConfiguration
If you use an ssh config file you can load your authentication and configuration from it as follows:
<?php $configuration = new Ssh\SshConfigFileConfiguration('~/.ssh/config', 'my-host'); $session = new Session($configuration, $configuration->getAuthentication());
This will pick up your public and private keys from your config file Host and Identity declarations.
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();
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 $exec = $session->getExec(); echo $exec->run('ls -lah');
See the Ssh\Exec class for more details.
herzult/php-ssh 适用场景与选型建议
herzult/php-ssh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16M 次下载、GitHub Stars 达 358, 最近一次更新时间为 2012 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ssh」 「ssh2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 herzult/php-ssh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 herzult/php-ssh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 herzult/php-ssh 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides an object-oriented wrapper for the PHP SSH2 extension.
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
Altax is an extensible deployment tool for PHP.
Cisco IOS communications and configuration parsing library
Interactive SSH2 suite for PHP 5.4
Dazzle Asynchronous SSH.
统计信息
- 总下载量: 1.16M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 365
- 点击次数: 20
- 依赖项目数: 22
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-09