manage ssh connections to server, create keys, run processes and log results currently in development
To install the package simply run
$ composer require legobox-co/quick-ssh
Next, proceed to register the service provider in order to have the package visible to your app. In config/app.php, alongside it's facade for easy accessibility
<?php
...
return [
'providers' => [
...
Legobox\QuickSsh\SshServiceProvider::class,
...
],
'aliases' => [
...
'QuickSsh' => 'Legobox\QuickSsh\Facades\QuickSsh::class',
...
]
]
Next you can proceed to publish the configuration so you can change the defaults.
$ php artisan vendor:publish --provider="Legobox\QuickSsh\SshServiceProvider"
Lets see how to use the library
In order to create an ssh key pair
use QuickSsh;
$keys = QuickSsh::createKeys($value = null);
$keys->publicKey // return the public key
$keys->privateKey // return the private key
use QuickSsh;
// server options host, keytext, username
$serverInstance = QuickSsh::connector($serverOptions)->connect();
To run commands on your default remote connection, use the run method on your instance:
$serverInstance->run([
'cd /var/www',
'git pull origin master',
]);
You may catch the "live" output of your remote commands by passing a Closure into the run method:
$serverInstance->run($commands, function($line)
{
echo $line.PHP_EOL;
});
If you need to define a group of commands that should always be run together, you may use the define method to define a task:
$serverInstance->define('deploy', [
'cd /var/www',
'git pull origin master',
'php artisan migrate',
]);
Once the task has been defined, you may use the task method to run it:
$serverInstance->task('deploy', function($line)
{
echo $line.PHP_EOL;
});
The instance includes a simple way to download files using the get and getString methods:
$serverInstance->get($remotePath, $localPath);
$contents = $serverInstance->getString($remotePath);
The SSH class also includes a simple way to upload files, or even strings, to the server using the put and putString methods:
$serverInstance->put($localFile, $remotePath);
$serverInstance->putString($remotePath, 'Foo');