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

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

rocketeers-app/ssh
==================

A lightweight package to execute commands over an SSH connection

01.4k↓50%[1 PRs](https://github.com/rocketeers-app/ssh/pulls)PHP

Since Mar 26Pushed 2y agoCompare

[ Source](https://github.com/rocketeers-app/ssh)[ Packagist](https://packagist.org/packages/rocketeers-app/ssh)[ RSS](/packages/rocketeers-app-ssh/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

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

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);
```

### Setting a timeout

[](#setting-a-timeout)

You can set a timeout for the command.

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

### Specifying a jump host

[](#specifying-a-jump-host)

If using a jump/proxy/bastion host, the `useJumpHost` function allows you to set the jump hosts details:

```
Ssh::create('user', 'host')->useJumpHost("$jumpuser@$jumphost:$jumpport");
```

### Using SSH multiplexing

[](#using-ssh-multiplexing)

If making many connections to the same host, SSH multiplexing enables re-using one TCP connection. Call `useMultiplexing` function to set control master options:

```
Ssh::create('user', 'host')->useMultiplexing($controlPath, $controlPersist);

// Ssh::create('user', 'host')->useMultiplexing('/home/.ssh/control_masters/%C', '15m');
```

### 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();
```

### Enable quiet mode

[](#enable-quiet-mode)

By default, the quiet mode is disabled. You can enable quiet mode using `enableQuietMode`.

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

### Disable Password Authentication

[](#disable-password-authentication)

By default, the password authentication is enabled. You can disable password authentication using `disablePasswordAuthentication`.

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

### 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 an 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 your command produces output by passing a closure to `onOutput`.

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

Whenever there is output that closure 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

### Windows Target

[](#windows-target)

If your target is a Windows machine, you can use the `removeBash` method to remove the bash command from the command line.

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

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  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)
- [Mar van Eijk](https://github.com/markvaneijk)
- [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

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 52.4% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c6a425dc8645907a118a007438172d58c2016773f54ab3a834beff172632f13?d=identicon)[ux](/maintainers/ux)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (97 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (6 commits)")[![yob-yob](https://avatars.githubusercontent.com/u/25021150?v=4)](https://github.com/yob-yob "yob-yob (5 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (5 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (5 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (4 commits)")[![SamuelNitsche](https://avatars.githubusercontent.com/u/24483576?v=4)](https://github.com/SamuelNitsche "SamuelNitsche (4 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (4 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (4 commits)")[![markvaneijk](https://avatars.githubusercontent.com/u/1925388?v=4)](https://github.com/markvaneijk "markvaneijk (4 commits)")[![zaherg](https://avatars.githubusercontent.com/u/27624?v=4)](https://github.com/zaherg "zaherg (3 commits)")[![MatusBoa](https://avatars.githubusercontent.com/u/8343385?v=4)](https://github.com/MatusBoa "MatusBoa (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)")[![bomas13](https://avatars.githubusercontent.com/u/4661591?v=4)](https://github.com/bomas13 "bomas13 (2 commits)")[![bambamboole](https://avatars.githubusercontent.com/u/8823695?v=4)](https://github.com/bambamboole "bambamboole (2 commits)")[![iPwnPancakes](https://avatars.githubusercontent.com/u/13839270?v=4)](https://github.com/iPwnPancakes "iPwnPancakes (2 commits)")[![ebulku](https://avatars.githubusercontent.com/u/11932725?v=4)](https://github.com/ebulku "ebulku (2 commits)")

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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