A new PHP package released by the fine folks at Spatie is spatie/ssh
. Leveraging Symfony\Component\Process\Process
it allows you to execute commands over SSH from within your PHP code.
spatie/ssh
is probably the easiest way to perform a quick SSH command. It doesn’t have a lot of features, but that’s ok. It’s intended as something very lightweight.
$process = Ssh::create('user', 'example.com')
->usePort(2222)
->usePrivateKey('/home/user/.ssh/id_rsa')
->execute('your favorite command');
Also comes with download
and upload
functions, using scp
under the hood.
Installation per composer:
composer require spatie/ssh
how to pass password
this command execute on server without any password? just with username?