All Projects → spatie → Ssh

spatie / Ssh

Licence: mit
A lightweight package to execute commands over an SSH connection

Labels

Projects that are alternatives of or similar to Ssh

Asuswrt Merlin Transparent Proxy
transparent proxy base on ss, v2ray, ipset, iptables, chinadns on asuswrt merlin.
Stars: ✭ 367 (-21.58%)
Mutual labels:  ssh
Yubikey
YubiKey at Datadog
Stars: ✭ 393 (-16.03%)
Mutual labels:  ssh
Pi Timolo
Raspberry PI-TIMOLO ( PI-TImelapse, MOtion, LOwLight ) uses RPI picamera and OpenCV for Remote Headless Security Monitoring using Motion Tracking, Rclone Auto Sync files with remote storage services. Auto Twilight Transitions and Low Light Camera Settings. Panoramic images using PanTiltHat and More. This project is featured on GitHub Awesome software.
Stars: ✭ 441 (-5.77%)
Mutual labels:  ssh
Openiothub
💖A free IoT (Internet of Things) platform and private cloud. [一个免费的物联网和私有云平台,支持内网穿透]
Stars: ✭ 371 (-20.73%)
Mutual labels:  ssh
Python code samples network
A collection of Python Code Samples for Network Management. Includes samples to run on-box and off-box.
Stars: ✭ 384 (-17.95%)
Mutual labels:  ssh
Trezor Agent
Hardware-based SSH/PGP agent
Stars: ✭ 400 (-14.53%)
Mutual labels:  ssh
Sharkey
Sharkey is a service for managing certificates for use by OpenSSH
Stars: ✭ 360 (-23.08%)
Mutual labels:  ssh
Ssh Chat
Chat over SSH.
Stars: ✭ 4,512 (+864.1%)
Mutual labels:  ssh
Storm
Manage your SSH like a boss.
Stars: ✭ 3,865 (+725.85%)
Mutual labels:  ssh
Mina
Blazing fast application deployment tool.
Stars: ✭ 4,196 (+796.58%)
Mutual labels:  ssh
Bridgy
cloud inventory + ssh + tmux + sshfs
Stars: ✭ 374 (-20.09%)
Mutual labels:  ssh
Wsl Ssh Pageant
A Pageant -> TCP bridge for use with WSL, allowing for Pageant to be used as an ssh-ageant within the WSL environment.
Stars: ✭ 381 (-18.59%)
Mutual labels:  ssh
Bastillion Ec2
A web-based SSH console to execute commands and manage multiple EC2 instances simultaneously running on Amazon Web Services (AWS).
Stars: ✭ 410 (-12.39%)
Mutual labels:  ssh
Ssh Agent
GitHub Action to setup `ssh-agent` with a private key
Stars: ✭ 365 (-22.01%)
Mutual labels:  ssh
Ssh Permit A38
Central management and deployment for SSH keys
Stars: ✭ 451 (-3.63%)
Mutual labels:  ssh
Logistics manage system
基于Java 中 SSH 框架的 物流配送管理系统 同时为本人的大学毕业设计 | QQ群 838664086
Stars: ✭ 365 (-22.01%)
Mutual labels:  ssh
Ansible Role Security
Ansible Role - Security
Stars: ✭ 398 (-14.96%)
Mutual labels:  ssh
Phpseclib
PHP Secure Communications Library
Stars: ✭ 4,627 (+888.68%)
Mutual labels:  ssh
Gbt
Highly configurable prompt builder for Bash, ZSH and PowerShell written in Go.
Stars: ✭ 457 (-2.35%)
Mutual labels:  ssh
Exodus
network proxy and tunnel (VPN)
Stars: ✭ 432 (-7.69%)
Mutual labels:  ssh

A lightweight package to execute commands over an SSH connection

Latest Version on Packagist GitHub Tests Action Status Quality Score Total Downloads

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', 'example.com')->execute('your favorite command');

It will return an instance of Symfony's Process.

If you don't want to wait until the execute commands complete, you can call executeAsync

$process = Ssh::create('user', 'example.com')->executeAsync('your favorite command');

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', 'example.com')->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');

Disable Strict host key checking

By default, strict host key checking is enabled. You can disable strict host key checking using disableStrictHostKeyChecking.

Ssh::create('user', 'host')->disableStrictHostKeyChecking();

Enable quiet mode

By default, the quiet mode is disabled. You can enable quiet mode using enableQuietMode.

Ssh::create('user', 'host')->enableQuietMode();

Disable Password Authentication

By default, the password authentication is enabled. You can disable password authentication using disablePasswordAuthentication.

Ssh::create('user', 'host')->disablePasswordAuthentication();

Uploading & downloading files and directories

You can upload files & directories to a host using:

Ssh::create('user', 'host')->upload('path/to/local/file', 'path/to/host/file');

Or download them:

Ssh::create('user', 'host')->download('path/to/host/file', 'path/to/local/file');

Under the hood the process will use scp.

Modifying the Symfony process

Behind the scenes all commands will be performed using Symfonys Process.

You can configure to the Process by using the configureProcess method. Here's an example where we disable the timeout.

Ssh::create('user', 'host')->configureProcess(fn (Process $process) => $process->setTimeout(null));

Immediately responding to output

You can get notified whenever your command produces output by passing a closure to onOutput.

Ssh::create('user', 'host')->onOutput(fn($type, $line) => echo $line)->execute('whoami');

Whenever there is output that closure will get called with two parameters:

  • type: this can be Symfony\Component\Process\Process::OUT for regular output and Symfony\Component\Process\Process::ERR for error output
  • line: the output itself

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.

Alternatives

If you need some more features, take a look at DivineOmega/php-ssh-connection.

Credits

The Ssh class contains code taken from laravel/envoy

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].