Laravel Process over SSH
is a Laravel package that extends the Illuminate\Process
functionality to allow command execution via SSH.
- 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.
Install the package via Composer:
composer require lguichard/process-ssh
To execute a command over SSH, use the Process
facade:
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();
}
$result = Process::ssh([
'host' => '192.168.1.10',
'user' => 'username',
'private_key' => '/path/to/private_key',
])
->run('ls -al');
$result = Process::ssh([
'host' => '192.168.1.10',
'user' => 'username',
'private_key' => '/path/to/private_key',
])
->disableStrictHostKeyChecking()
->run('ls -al');
$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');
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');
});
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();
}
To run the package's tests:
composer test
Contributions are welcome! Please submit a pull request or open an issue on GitHub.
This package is open-source software licensed under the MIT license.
For more details, visit the GitHub repository.
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.