jord-jd/php-ssh-connection 问题修复 & 功能扩展

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

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

jord-jd/php-ssh-connection

最新稳定版本:v4.0.0

Composer 安装命令:

composer require jord-jd/php-ssh-connection

包简介

Provides an elegant syntax to connect to SSH servers and execute commands.

README 文档

README

Tests

The PHP SSH Connection package provides an elegant syntax to connect to SSH servers and execute commands. It supports password and public-private key authentication, and can capture command output and errors.

Supported runtimes: PHP 7.2+ and PHP 8.x.

Installation

Install with Composer:

composer require jord-jd/php-ssh-connection

Usage

$connection = (new SSHConnection())
            ->to('test.rebex.net')
            ->onPort(22)
            ->as('demo')
            ->withPassword('password')
         // ->withPrivateKey($privateKeyPath)
         // ->withPrivateKeyString($privateKeyContents)
         // ->timeout(30)
            ->connect();

$command = $connection->run('echo "Hello world!"');

$command->getOutput();  // 'Hello world!'
$command->getError();   // ''

$connection->upload($localPath, $remotePath);
$connection->download($remotePath, $localPath); // supports recursive directory downloads

Running multiple commands

Each run() call executes in a fresh shell context. If you need stateful command execution (for example cd then touch), use runCommands():

$connection->runCommands([
    'cd /var/www/html',
    'mkdir -p app',
    'cd app',
    'touch index.php',
]);

Fingerprint verification

For security, you can fingerprint the remote server and verify it remains the same across connections.

$fingerprint = $connection->fingerprint(); // defaults to MD5 for backward compatibility

if ($newConnection->fingerprint() !== $fingerprint) {
    throw new Exception('Fingerprint does not match!');
}

Available fingerprint types:

$md5Fingerprint    = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5);
$sha1Fingerprint   = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);
$sha256Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA256);
$sha512Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA512);

Testing

The package test suite includes SSH integration tests. Set these variables before running tests:

  • RUN_SSH_INTEGRATION_TESTS=1
  • SSH_TEST_HOST
  • SSH_TEST_PORT
  • SSH_TEST_USER
  • SSH_TEST_PRIVATE_KEY_PATH or SSH_TEST_PRIVATE_KEY_CONTENTS
  • SSH_TEST_PASSWORD (only required for password-auth test)

Then run:

vendor/bin/phpunit

统计信息

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

GitHub 信息

  • Stars: 111
  • Watchers: 0
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2026-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固