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

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

aleex1848/ssh
=============

A lightweight package to execute commands over an SSH connection

1.1.0(6mo ago)188MITPHPPHP ^8.2

Since Feb 23Pushed 6mo agoCompare

[ Source](https://github.com/aleex1848/ssh)[ Packagist](https://packagist.org/packages/aleex1848/ssh)[ Docs](https://github.com/spatie/ssh)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/aleex1848-ssh/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (4)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)[![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)

[![](https://camo.githubusercontent.com/fd5a0d0c274733f8bb13285d303f965eab3223d982c521b7aebaeabbd70a7238/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7373682e6a70673f743d31)](https://spatie.be/github-ad-click/ssh)

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

### 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)
- [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

39

—

LowBetter than 86% of packages

Maintenance66

Regular maintenance activity

Popularity11

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.9% 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 ~303 days

Total

3

Last Release

206d ago

PHP version history (2 changes)1.0PHP ^7.4|^8.0

1.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/63e44afea1761535641e0dff72e8f81e4fa9a56f7094f2193813f5f3cf6877e4?d=identicon)[aleex1848](/maintainers/aleex1848)

---

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)")[![aleex1848](https://avatars.githubusercontent.com/u/17452861?v=4)](https://github.com/aleex1848 "aleex1848 (6 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (5 commits)")[![yob-yob](https://avatars.githubusercontent.com/u/25021150?v=4)](https://github.com/yob-yob "yob-yob (5 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (5 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)")[![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)")[![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)")

---

Tags

spatiessh

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[spatie/laravel-webhook-client

Receive webhooks in Laravel apps

1.2k11.7M65](/packages/spatie-laravel-webhook-client)[spatie/db-dumper

Dump databases

1.2k25.9M69](/packages/spatie-db-dumper)[spatie/ssh

A lightweight package to execute commands over an SSH connection

8322.8M41](/packages/spatie-ssh)[spatie/guzzle-rate-limiter-middleware

A rate limiter for Guzzle

1675.0M29](/packages/spatie-guzzle-rate-limiter-middleware)[altayalp/ftp-client

FTP and SFTP client for Php

1971.3k](/packages/altayalp-ftp-client)

PHPackages © 2026

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