PHPackages                             bitller/ssh - 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. bitller/ssh

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bitller/ssh
===========

A lightweight package to execute commands over an SSH connection

1.4.0(6y ago)02.4k1MITPHPPHP ^7.4

Since Feb 3Pushed 4y agoCompare

[ Source](https://github.com/bitller/ssh)[ Packagist](https://packagist.org/packages/bitller/ssh)[ Docs](https://github.com/spatie/ssh)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/bitller-ssh/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

A lightweight package to execute commands over an SSH connection
================================================================

[](#a-lightweight-package-to-execute-commands-over-an-ssh-connection)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8a8a60d190c1fad4ac2312b567e5d1908829ca8926f32a6e70f9f33106a1b9ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f7373682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/ssh)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8b1fc983ffd1f6f030e6771f5c3ebf6300c2ad9b55b8900e1762b146f3b2498b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f7373682f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/spatie/ssh/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Quality Score](https://camo.githubusercontent.com/c9565d67d2a379b3ff56a90f84cb8edd6e7ff31588af94abc12f6c1912af0e6c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f7373682e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/ssh)[![Total Downloads](https://camo.githubusercontent.com/684e031e39f68ec8010671284f36791c6bb211a865b51e53d3b5a5f137bcfca9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7373682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/ssh)

You can execute an SSH command like this:

```
Ssh::create('user', 'host')->execute('your favorite command');
```

It will return an instance of [Symfony's `Process`](https://symfony.com/doc/current/components/process.html).

Support us
----------

[](#support-us)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/ssh
```

Usage
-----

[](#usage)

You can execute an SSH command like this:

```
$process = Ssh::create('user', 'example.com')->execute('your favorite command');
```

It will return an instance of [Symfony's `Process`](https://symfony.com/doc/current/components/process.html).

If you don't want to wait until the execute commands complete, you can call `executeAsync`

```
$process = Ssh::create('user', 'example.com')->executeAsync('your favorite command');
```

### Getting the result of a command

[](#getting-the-result-of-a-command)

To check if your command ran ok

```
$process->isSuccessful();
```

This is how you can get the output

```
$process->getOutput();
```

### Running multiple commands

[](#running-multiple-commands)

To run multiple commands pass an array to the execute method.

```
$process = Ssh::create('user', 'example.com')->execute([
   'first command',
   'second command',
]);
```

### Choosing a port

[](#choosing-a-port)

You can choose a port by passing it to the constructor.

```
$port = 123;

Ssh::create('user', 'host', $port);
```

Alternatively you can use the `usePort` function:

```
Ssh::create('user', 'host')->usePort($port);
```

### Specifying the private key to use

[](#specifying-the-private-key-to-use)

You can use `usePrivateKey` to specify a path to a private SSH key to use.

```
Ssh::create('user', 'host')->usePrivateKey('/home/user/.ssh/id_rsa');
```

### Disable Strict host key checking

[](#disable-strict-host-key-checking)

By default, strict host key checking is enabled. You can disable strict host key checking using `disableStrictHostKeyChecking`.

```
Ssh::create('user', 'host')->disableStrictHostKeyChecking();
```

### Uploading &amp; downloading files and directories

[](#uploading--downloading-files-and-directories)

You can upload files &amp; directories to a host using:

```
Ssh::create('user', 'host')->upload('path/to/local/file', 'path/to/host/file');
```

Or download them:

```
Ssh::create('user', 'host')->download('path/to/host/file', 'path/to/local/file');
```

Under the hood the process will use `scp`.

### Modifying the Symfony process

[](#modifying-the-symfony-process)

Behind the scenes all commands will be performed using [Symfonys `Process`](https://symfony.com/doc/current/components/process.html).

You can configure to the `Process` by using the `configureProcess` method. Here's and example where we disable the timeout.

```
Ssh::create('user', 'host')->configureProcess(fn (Process $process) => $process->setTimeout(null));
```

### Immediately responding to output

[](#immediately-responding-to-output)

You can get notified whenever you command produces output by setting by passing a closure to `onOutput`.

```
Ssh::create('user', 'host')->onOutput(fn($type, $line) => echo $line)->execute('whoami');
```

Whenever there is output that close will get called with two parameters:

- `type`: this can be `Symfony\Component\Process\Process::OUT` for regular output and `Symfony\Component\Process\Process::ERR` for error output
- `line`: the output itself

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Alternatives
------------

[](#alternatives)

If you need some more features, take a look at [DivineOmega/php-ssh-connection](https://github.com/DivineOmega/php-ssh-connection).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

The `Ssh` class contains code taken from [laravel/envoy](https://laravel.com/docs/6.x/envoy)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 56.3% 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 ~8 days

Recently: every ~15 days

Total

9

Last Release

2265d ago

Major Versions

0.0.1 → 1.0.02020-02-04

1.1.0 → v2.x-dev2020-02-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/e711cc892d5edc8721fc425a8c03952f7fedc440425f5abea3029fcd25e6bd1e?d=identicon)[saas-estate](/maintainers/saas-estate)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (54 commits)")[![mezuky04](https://avatars.githubusercontent.com/u/7033003?v=4)](https://github.com/mezuky04 "mezuky04 (7 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (5 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (5 commits)")[![SamuelNitsche](https://avatars.githubusercontent.com/u/24483576?v=4)](https://github.com/SamuelNitsche "SamuelNitsche (4 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (4 commits)")[![zaherg](https://avatars.githubusercontent.com/u/27624?v=4)](https://github.com/zaherg "zaherg (3 commits)")[![rodelias-frete](https://avatars.githubusercontent.com/u/281798633?v=4)](https://github.com/rodelias-frete "rodelias-frete (3 commits)")[![mazedlx](https://avatars.githubusercontent.com/u/9453522?v=4)](https://github.com/mazedlx "mazedlx (3 commits)")[![pkboom](https://avatars.githubusercontent.com/u/13960169?v=4)](https://github.com/pkboom "pkboom (2 commits)")[![michaelaguiar](https://avatars.githubusercontent.com/u/138890?v=4)](https://github.com/michaelaguiar "michaelaguiar (1 commits)")[![imliam](https://avatars.githubusercontent.com/u/4326337?v=4)](https://github.com/imliam "imliam (1 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (1 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")[![MohammedAlkutrani](https://avatars.githubusercontent.com/u/24508555?v=4)](https://github.com/MohammedAlkutrani "MohammedAlkutrani (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")

---

Tags

spatiessh

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bitller-ssh/health.svg)

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[spatie/crawler

Crawl all internal links found on a website

2.8k17.7M58](/packages/spatie-crawler)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M152](/packages/spatie-laravel-health)[spatie/db-dumper

Dump databases

1.2k28.0M83](/packages/spatie-db-dumper)[spatie/flare-client-php

Send PHP errors to Flare

177156.9M21](/packages/spatie-flare-client-php)[spatie/laravel-webhook-client

Receive webhooks in Laravel apps

1.2k12.7M121](/packages/spatie-laravel-webhook-client)

PHPackages © 2026

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