michaelaguiar / ssh

A lightweight package to execute commands over an SSH connection

Home Page:https://spatie.be/open-source

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

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

It will return an instance of Symfony's Process.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

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. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/ssh

Usage

You can execute an SSH command like this:

$process = Ssh::create('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 = Ssh::create('user', 'host')->execute([
   'first command',
   'second command',
]);

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

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

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

License

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

About

A lightweight package to execute commands over an SSH connection

https://spatie.be/open-source

License:MIT License


Languages

Language:PHP 100.0%