lguichard / process-ssh
Package to use Laravel Process over SSH connections
Fund package maintenance!
lguichard
www.paypal.com/paypalme/lguichard01
Requires
- php: ^8.1
- illuminate/support: ^10.0 || ^11.0
Requires (Dev)
- laravel/pint: ^1.18.1
- orchestra/testbench: ^9.9
- pestphp/pest: ^3.5.1
- pestphp/pest-plugin-watch: ^3.0
- phpstan/phpstan: ^1.12.7
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
README
Laravel Process over SSH
Laravel Process over SSH
is a Laravel package that extends the Illuminate\Process
functionality to allow command execution via SSH.
Features
- Execute shell commands on remote servers using SSH.
- Full compatibility with Laravel's
Process
features. - Easily configurable options like custom ports, passwords, private keys, and more.
Installation
Install the package via Composer:
composer require lguichard/process-ssh
Usage
To execute a command over SSH, use the Process
facade:
Basic Usage
use Illuminate\Support\Facades\Process; $result = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'password' => 'your_password', ]) ->run('ls -al'); if ($result->successful()) { echo $result->output(); } else { echo $result->errorOutput(); }
Using Private Key Authentication
$result = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'private_key' => '/path/to/private_key', ]) ->run('ls -al');
Disabling Strict Host Key Checking
$result = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'private_key' => '/path/to/private_key', ]) ->disableStrictHostKeyChecking() ->run('ls -al');
Adding Extra SSH Options
$result = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'private_key' => '/path/to/private_key', ]) ->addExtraOption('-o LogLevel=ERROR') ->addExtraOption('-o ConnectTimeout=10') ->run('ls -al');
Use the favorites method provided by Laravel's Process class.
For more information, refer to the official documentation : https://laravel.com/docs/11.x/processes
$process = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'password' => 'your_password', ]) ->start('bash import.sh'); $result = $process->wait();
[$result1, $result2] = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'password' => 'your_password', ]) ->concurrently(function (Pool $pool) { $pool->command('ls -al'); $pool->command('whoami'); });
$result = Process::ssh([ 'host' => '192.168.1.10', 'user' => 'username', 'password' => 'your_password', ]) ->pool(function (Pool $pool) { $pool->command('ls -al'); $pool->command('whoami'); });
SSH multiplexing
If you want to execute multiple commands over the same SSH connection, SSH multiplexing allows you to reuse an existing TCP connection, improving efficiency and reducing overhead.
$process = Process::ssh([ 'host' => '192.168.85.5', 'user' => 'ubuntu', 'port' => 22, ])->useMultiplexing(); $commands = [ 'ls -al', 'whoami', 'pwd', 'uname -a', 'df -h', 'top -bn1', 'cat /etc/os-release', 'netstat -tuln', 'uptime', 'tail -n 20 /var/log/syslog', ]; foreach ($commands as $command) { $process->run($command)->output(); }
Testing
To run the package's tests:
composer test
Contributing
Contributions are welcome! Please submit a pull request or open an issue on GitHub.
License
This package is open-source software licensed under the MIT license.
For more details, visit the GitHub repository.
Acknowledgments
Special thanks to Spatie's SSH package for inspiring the creation of this package.
Skeleton PHP was created by Nuno Maduro under the MIT license.