spatie/ssh

A lightweight package to execute commands over an SSH connection


Keywords
ssh, spatie, php
License
MIT

Documentation

A lightweight package to execute commands over an SSH connection

Latest Version on Packagist GitHub Tests Action Status Quality Score Total Downloads

You can execute an SSH command like this:

(new Ssh('user', 'host'))->execute('your favorite command');

It will return an instance of Symfony's Process.

Installation

You can install the package via composer:

composer require spatie/ssh

Usage

You can execute an SSH command like this:

$process = (new Ssh('user', 'host'))->execute('your favorite command');

It will return an instance of Symfony's Process.

Getting the result of a command

To check if your command ran ok

$process->isSuccessfull();

This is how you can get the output

$process->getOutput();

Running multiple commands

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

$process = (new Ssh('user', 'host'))->execute([
   'first command',
   'second command',
]);

Choosing a port

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

$port = 123;

(new Ssh('user', 'host', $port));

Alternatively you can use the port function:

(new Ssh('user', 'host'))->usePort($port);

Specifying the public key to use

You can use usePublicKey to specify a path to a public key to use.

(new Ssh('user', 'host'))->usePublicKey('/home/user/.ssh/id_rsa');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

The Ssh class contains code taken from laravel/envoy

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

The MIT License (MIT). Please see License File for more information.