PHPackages                             divineomega/php-ssh-connection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. divineomega/php-ssh-connection

Abandoned → [jord-jd/php-ssh-connection](/?search=jord-jd%2Fphp-ssh-connection)Library[HTTP &amp; Networking](/categories/http)

divineomega/php-ssh-connection
==============================

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

v5.0.0(1mo ago)110112.4k↓66%211LGPL-3.0-onlyPHPPHP &gt;=7.2CI passing

Since Jul 31Pushed 1mo agoCompare

[ Source](https://github.com/Jord-JD/php-ssh-connection)[ Packagist](https://packagist.org/packages/divineomega/php-ssh-connection)[ GitHub Sponsors](https://github.com/DivineOmega)[ RSS](/packages/divineomega-php-ssh-connection/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (13)Used By (1)

PHP SSH Connection
==================

[](#php-ssh-connection)

[![Tests](https://github.com/Jord-JD/php-ssh-connection/actions/workflows/tests.yml/badge.svg)](https://github.com/Jord-JD/php-ssh-connection/actions/workflows/tests.yml)[![Packagist](https://camo.githubusercontent.com/a35f4a23bd9720af5150134ea10e8fc4b764b31e3cc86a85e3331b6aa1a71df3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f72642d6a642f7068702d7373682d636f6e6e656374696f6e2e737667)](https://packagist.org/packages/jord-jd/php-ssh-connection)

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
------------

[](#installation)

Install with Composer:

```
composer require jord-jd/php-ssh-connection
```

Usage
-----

[](#usage)

```
$connection = (new SSHConnection())
            ->to('test.rebex.net')
            ->onPort(22)
            ->as('demo')
            ->withPassword('password')
         // ->withPrivateKey($privateKeyPath)
         // ->withPrivateKeyString($privateKeyContents)
         // ->withPrivateKey($encryptedPrivateKeyPath, $passphrase)
         // ->withExpectedFingerprint('SHA256:base64-fingerprint-from-a-trusted-source')
         // ->timeout(30)
            ->connect();

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

$command->getOutput();  // 'Hello world!'
$command->getError();   // ''
$command->getExitStatus(); // 0
$command->isSuccessful();  // true
$command->hasTimedOut();   // false

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

### Running multiple commands

[](#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

[](#fingerprint-verification)

For security, obtain the server's SHA-256 fingerprint through a trusted out-of-band channel and configure it before connecting. Verification happens before a password or private key is sent to the server.

```
$connection = (new SSHConnection())
    ->to('example.com')
    ->as('username')
    ->withPrivateKey('/home/user/.ssh/id_rsa')
    ->withExpectedFingerprint('SHA256:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU')
    ->connect();
```

The `SHA256:` prefix and base64 padding are optional when configuring the expected value. MD5 values may be supplied with or without colons.

Available fingerprint types:

```
$md5Fingerprint    = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5); // colon-separated hex
$sha1Fingerprint   = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);
$sha256Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA256); // OpenSSH base64
$sha512Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA512);
$openSshPublicKey  = $connection->hostPublicKey();
```

SHA-256 and MD5 match the standard OpenSSH fingerprint algorithms. SHA-1 and SHA-512 remain available as hexadecimal hashes of the SSH wire key for callers that previously selected those constants. The no-argument `fingerprint()` call still defaults to MD5 for source compatibility; SHA-256 is recommended for new code.

### Private key passphrases

[](#private-key-passphrases)

Pass a private-key passphrase as the second argument for either file or string keys:

```
$connection->withPrivateKey('/secure/id_rsa', 'key passphrase');
$connection->withPrivateKeyString($privateKeyContents, 'key passphrase');
```

### Timeouts

[](#timeouts)

`timeout()` now applies to the initial socket connection and authentication as well as subsequent command and SFTP activity. A timeout of zero disables the operation timeout; negative values are rejected.

### File transfer safety

[](#file-transfer-safety)

Uploads and downloads both use SFTP. Recursive directory downloads refuse to follow remote symbolic links, preventing cycles and unexpected traversal outside the requested tree.

Compatibility
-------------

[](#compatibility)

PHP 7.2 through the current PHP 8.x releases are supported. Version 5 uses the actively maintained phpseclib 3.x line.

### Upgrading to 5.0

[](#upgrading-to-50)

- Composer now installs phpseclib 3.x instead of 2.x.
- MD5 and SHA-256 fingerprints now use standard OpenSSH representations rather than hashes of a truncated host-key string.
- Uploads use SFTP instead of the removed phpseclib 2 SCP client.
- Empty hostnames/usernames, out-of-range ports, negative timeouts, invalid key passphrases, and recursive remote symbolic links now fail explicitly.

Testing
-------

[](#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
```

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance94

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 91.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Recently: every ~616 days

Total

12

Last Release

32d ago

Major Versions

v1.3.1 → v2.0.02019-08-08

v2.2.0 → v3.0.02026-02-14

v3.0.0 → v4.0.02026-02-16

v4.0.0 → v5.0.02026-07-18

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v4.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/c580cdf7c14898fff179cdfc1085892091d5d2f49d917873a12365af9ac77c93?d=identicon)[Jord-JD](/maintainers/Jord-JD)

---

Top Contributors

[![Jord-JD](https://avatars.githubusercontent.com/u/650645?v=4)](https://github.com/Jord-JD "Jord-JD (65 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![sboesch](https://avatars.githubusercontent.com/u/16945695?v=4)](https://github.com/sboesch "sboesch (2 commits)")[![EdwinHoksberg](https://avatars.githubusercontent.com/u/6866019?v=4)](https://github.com/EdwinHoksberg "EdwinHoksberg (1 commits)")[![sonaldo](https://avatars.githubusercontent.com/u/3761019?v=4)](https://github.com/sonaldo "sonaldo (1 commits)")

---

Tags

phpsshssh-clientssh-client-library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/divineomega-php-ssh-connection/health.svg)

```
[![Health](https://phpackages.com/badges/divineomega-php-ssh-connection/health.svg)](https://phpackages.com/packages/divineomega-php-ssh-connection)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k113.1M997](/packages/laravel-socialite)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[leantime/leantime

Open source project management system for non-project managers. Simple like Trello, powerful like Jira. Built with neurodiversity in mind.

11.3k4.0k](/packages/leantime-leantime)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

762297.9k53](/packages/civicrm-civicrm-core)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M674](/packages/shopware-core)[shopware/administration

Administration frontend for the Shopware Core

404.5M135](/packages/shopware-administration)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
