2017 © Pedro PelĂĄez
 

library php-ssh

Provides an object-oriented wrapper for the php ssh2 extension.

image

luka/php-ssh

Provides an object-oriented wrapper for the php ssh2 extension.

  • Thursday, July 12, 2018
  • by tux-rampage
  • Repository
  • 2 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 82 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

PHP SSH

Build Status (develop), (*1)

Provides an object-oriented wrapper for the php ssh2 extension. This is based on the work of Antoine Hérault., (*2)

Requirements

You need PHP version 7.1+ with the SSH2 extension., (*3)

Installation

The best way to add the library to your project is using composer., (*4)

$ composer require luka/php-ssh:^2.0

Usage

Configuration of the connection

To establish an SSH connection, you must first define its configuration. For that, create a Configuration instance with all the needed parameters., (*5)

<?php

// simple configuration to connect "my-host"
$configuration = new Ssh\HostConfiguration('my-host');

The available configuration classes are:, (*6)

  • Ssh\HostConfiguration
  • Ssh\OpenSSH\ConfigFile

Both connection configuration and public/private key authentication can be obtained from a ssh config file such as ~/.ssh/config, (*7)

<?php

// simple configuration to connect "my-host"
$configuration = Ssh\OpenSSH\ConfigFile::fromHostname('my-host', '~/.ssh/config');
$authentication = $configuration->createAuthenticationMethod('optional_passphrase', 'optional_username');

Create a session

The session is the central access point to the SSH functionality provided by the library., (*8)

<?php
// ... the configuration creation
$session = new Ssh\Session($configuration);

Authentication

The authentication classes allow you to authenticate over a SSH session. When you define an authentication for a session, it will authenticate on connection., (*9)

<?php

$configuration = new Ssh\HostConfiguration('myhost');
$authentication = new Ssh\Authentication\Password('John', 's3cr3t');

$session = new Session($configuration, $authentication);

The available authentication are:, (*10)

  • None for username based authentication
  • Password for password authentication
  • PublicKeyFile to authenticate using a public key
  • HostBasedFile to authenticate using a public hostkey
  • Agent to authenticate using an ssh-agent

Authentication from Ssh\OpenSSH\ConfigFile

If you use an ssh config file you can load your authentication and configuration from it as follows:, (*11)

<?php

$configuration = Ssh\OpenSSH\ConfigFile::fromHostname('my-host');
$session = new Ssh\Session($configuration, $configuration->createAuthenticationMethod());

This will pick up the username, and your public and private keys from your config file Host and Identity declarations., (*12)

This simple snippet only works if the User declaration is also present, and the private key does not require a pass phrase. If any of this is not the case you have to pass the missing values to the createAuthentication() method., (*13)

Subsystems

Once you are authenticated over a SSH session, you can use the subsystems., (*14)

Sftp

You can easily access the sftp subsystem of a session using the getSftp() method:, (*15)

<?php

// the session creation
$sftp = $session->getSftp();

See the Ssh\Sftp class for more details on the available methods., (*16)

Publickey

The session also provides the getPublickey() method to access the publickey subsystem:, (*17)

<?php

// ... the session creation
$publickey = $session->getPublickey();

The Public-Key subsystem allows you to provide multiple public keys to use for authentication. See the Ssh\Publickey class for more details on the available methods., (*18)

Exec

The session provides the getExec() method to access the exec subsystem, (*19)

<?php

// ... the session creation

/** @var Ssh\Session $session */
$exec = $session->getExec();
echo $exec->run('ls -lah')->getExitCode(), PHP_EOL;

See the Ssh\Exec class for more details., (*20)

The Versions

12/07 2018

dev-develop

dev-develop

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php ^7.1
  • ext-ssh2 ^1.0

 

The Development Requires

ssh ssh2

11/07 2018

dev-master

9999999-dev

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

17/03 2015

v1.1.1

1.1.1.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

19/10 2014

v1.1.0

1.1.0.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

20/08 2014

v1.0.1

1.0.1.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

11/08 2014

dev-bug/29

dev-bug/29

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

15/06 2014

v1.0.0

1.0.0.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

15/06 2014

v0.1.1

0.1.1.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2

04/03 2013

v0.1.0

0.1.0.0

Provides an object-oriented wrapper for the php ssh2 extension.

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-ssh2 *

 

The Development Requires

ssh ssh2