https://github.com/divineomega/php-ssh-connection
Provides an elegant syntax to connect to SSH servers and execute commands.
https://github.com/divineomega/php-ssh-connection
php ssh ssh-client ssh-client-library
Last synced: 10 months ago
JSON representation
Provides an elegant syntax to connect to SSH servers and execute commands.
- Host: GitHub
- URL: https://github.com/divineomega/php-ssh-connection
- Owner: DivineOmega
- License: lgpl-3.0
- Created: 2019-07-29T22:38:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-06-21T07:49:34.000Z (over 2 years ago)
- Last Synced: 2025-03-29T22:10:01.659Z (11 months ago)
- Topics: php, ssh, ssh-client, ssh-client-library
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 110
- Watchers: 2
- Forks: 22
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP SSH Connection
[](https://travis-ci.com/DivineOmega/php-ssh-connection)
[](https://coveralls.io/github/DivineOmega/php-ssh-connection?branch=master)
The PHP SSH Connection package provides an elegant syntax to connect to SSH servers and execute commands. It supports both password and public-private keypair authentication, and can easily capture command output and errors.
## Installation
You can install the PHP SSH Connection package by running the following Composer command.
```bash
composer require divineomega/php-ssh-connection
```
## Usage
See the following basic usage instructions.
```php
$connection = (new SSHConnection())
->to('test.rebex.net')
->onPort(22)
->as('demo')
->withPassword('password')
// ->withPrivateKey($privateKeyPath)
// ->timeout(0)
->connect();
$command = $connection->run('echo "Hello world!"');
$command->getOutput(); // 'Hello World'
$command->getError(); // ''
$connection->upload($localPath, $remotePath);
$connection->download($remotePath, $localPath);
```
For security, you can fingerprint the remote server and verify the fingerprint remains the same
upon each subsequent connection.
```php
$fingerprint = $connection->fingerprint();
if ($newConnection->fingerprint() != $fingerprint) {
throw new Exception('Fingerprint does not match!');
}
```
If you wish, you can specify the type of fingerprint you wish to retrieve.
```php
$md5Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5); // default
$sha1Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);
```