GitHub - spatie/ssh: A lightweight package to execute commands over an SSH conne...
source link: https://github.com/spatie/ssh
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
A lightweight package to execute commands over an SSH connection
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->isSuccessful();
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 [email protected] 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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK