Phpseclib: Securely Communicating with Remote Servers via PHP
PHP has an SSH2 library which provides access to resources (shell, remote exec, tunneling, file transfer) on a remote machine using a secure cryptographic transport. Objectively, it is a tedious and highly frustrating task for a developer to implement it due to its overwhelming configuration options and complex API with little documentation.
The phpseclib (PHP Secure Communications Library) package has a developer friendly API. It uses some optional PHP extensions if they’re available and falls back on an internal PHP implementation otherwise. To use this package, you don’t need any non-default PHP extensions installed.
composer require phpseclib/phpseclib
This will install the most recent stable version of the library via Composer.
Before diving in blindly, I’d like to list some use-cases appropriate for using this library:
- Executing deployment scripts on a remote server
- Downloading and uploading files via SFTP
- Generating SSH keys dynamically in an application
- Displaying live output for remote commands executed on a server
- Testing an SSH or SFTP connection
Connecting to the Remote Server
Using phpseclib, you can connect to your remote server with any of the following authentication methods:
- RSA key
- Password Protected RSA key
- Username and Password (Not recommended)
Continue reading %Phpseclib: Securely Communicating with Remote Servers via PHP%