PHPackages                             assghard/php-ssh-helper - 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. assghard/php-ssh-helper

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

assghard/php-ssh-helper
=======================

PHP SSH helper to executing commands on server via SSH protocol. Library provides simply using of SSH under PHP

123PHP

Since Feb 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/assghard/php-ssh-helper)[ Packagist](https://packagist.org/packages/assghard/php-ssh-helper)[ RSS](/packages/assghard-php-ssh-helper/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP SSH helper to executing commands on server via SSH protocol
===============================================================

[](#php-ssh-helper-to-executing-commands-on-server-via-ssh-protocol)

Composer library which provides simply using of SSH under PHP

Pre requirements
----------------

[](#pre-requirements)

- PHP installed
- composer installed
- PHP extensions installed: php-mbstring, php-xml
- php-ssh2 installed (#sudo apt-get install php-ssh2)

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

[](#installation)

**composer require assghard/php-ssh-helper --prefer-dist**

How to use
----------

[](#how-to-use)

Add library to use: **use Assghard\\SSH\\SSHhelper;**

```
$sshConfig = [
        'host' => '192.168.1.12', // server IP address
        'port' => 22, // SSH port
        'user' => 'root', // SSH username
        'password' => '12345' // SSH user password
];

$sshHelper = new SSHhelper($sshConfig); // do connect

$sshHelper->execSshCommand('mkdir testDir');
$sshHelper->ssh_chmod('testDir', 0777);
$sshHelper->execSshCommand('touch ./testDir/test.txt');
$sshHelper->ssh_copy_file('./testDir/test.txt', '/var/www/html/test/TEST.txt');
$sshHelper->ssh_delete_file('./testDir/test.txt');
$sshHelper->ssh_remove_dir('./testDir');

$sshHelper->disconnect();
```

### If you use Laravel 5+ you can add an alias in /config/app.php file

[](#if-you-use-laravel-5-you-can-add-an-alias-in-configappphp-file)

```
'aliases' => [
...
'SSHhelper' => Assghard\SSH\SSHhelper::class,
...
],
```

And in controller:

```
$sshConfig = [
        'host' => '192.168.1.12', // server IP address
        'port' => 22, // SSH port
        'user' => 'root', // SSH username
        'password' => '12345' // SSH user password
];

$sshHelper = new \SSHhelper($sshConfig);
$sshHelper->execSshCommand('mkdir TEST');
$sshHelper->disconnect();
```

### Dependency injection

[](#dependency-injection)

Add library to use: **use Assghard\\SSH\\SSHhelper;**

```
private $ssh;
public function __construct(SSHhelper $ssh) {
    $this->ssh = $ssh;
}

...
$sshConfig = [
        'host' => '192.168.1.12', // server IP address
        'port' => 22, // SSH port
        'user' => 'root', // SSH username
        'password' => '12345' // SSH user password
];
$this->ssh->setConfig($sshConfig);
$this->ssh->execSshCommand('mkdir TEST');
$this->ssh->disconnect();
...
```

Method list
-----------

[](#method-list)

- **setConfig()** - Setter which sets a server SSH configuration to helper
- **connect()** - Do ssh2\_connect to the remote server via SSH and set a connection stream. Method is using inside others methods.
- **disconnect()** - Do disconnect and free resources
- **execSshCommand()** - General execution method. Executes commands on server via SSH connection
- ssh\_chmod() - Change remote folder permissions
- ssh\_copy\_file() - Copy file on remote server from sourceFile location to destinationFile
- ssh\_delete\_file() - Deletes remote file (NOT a folder)
- ssh\_remove\_dir() - Removes remote folder

Tested on PHP 7.2 and Laravel 5.8
---------------------------------

[](#tested-on-php-72-and-laravel-58)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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/b91333587646cff624e5b17959370962f01f0bdc36987b963e784dbd1d19c29f?d=identicon)[assghard](/maintainers/assghard)

---

Top Contributors

[![assghard](https://avatars.githubusercontent.com/u/11836150?v=4)](https://github.com/assghard "assghard (9 commits)")

### Embed Badge

![Health badge](/badges/assghard-php-ssh-helper/health.svg)

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

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