{"id":33963745,"url":"https://github.com/faraweilyas/sshbunny","last_synced_at":"2025-12-12T22:46:57.918Z","repository":{"id":56981598,"uuid":"158971099","full_name":"faraweilyas/sshbunny","owner":"faraweilyas","description":"PHP library that provides an object-oriented wrapper to connect to SSH and run shell commands with the php ssh2 extension.","archived":false,"fork":false,"pushed_at":"2018-12-07T01:20:15.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-31T21:09:46.134Z","etag":null,"topics":["php","php-library","shell","shell-command","ssh","ssh-client"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faraweilyas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-24T20:27:18.000Z","updated_at":"2024-06-13T01:08:07.000Z","dependencies_parsed_at":"2022-08-21T10:50:20.309Z","dependency_job_id":null,"html_url":"https://github.com/faraweilyas/sshbunny","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/faraweilyas/sshbunny","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faraweilyas%2Fsshbunny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faraweilyas%2Fsshbunny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faraweilyas%2Fsshbunny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faraweilyas%2Fsshbunny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faraweilyas","download_url":"https://codeload.github.com/faraweilyas/sshbunny/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faraweilyas%2Fsshbunny/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27693985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-library","shell","shell-command","ssh","ssh-client"],"created_at":"2025-12-12T22:46:57.136Z","updated_at":"2025-12-12T22:46:57.907Z","avatar_url":"https://github.com/faraweilyas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sshbunny\nPHP library that provides an object-oriented wrapper to connect to SSH and run shell commands with the php ssh2 extension.\n\n# Requirements\n------------\n\n- PHP version 5.3+\n- [SSH2 extension](http://www.php.net/manual/en/book.ssh2.php).\n- [composer](http://getcomposer.org).\n\n# Install with composer\n------------\n\nThe best way to add the library to your project is using [composer](http://getcomposer.org).\n```bash\ncomposer require faraweilyas/sshbunny\n```\nor\n\n# Clone this repo\n\n```bash\ngit clone https://github.com/faraweilyas/sshbunny.git\n```\n\n# Configuration\n-------------\n\n`SSHBunny` constructor takes four parameters and they all have default values `$method='local'`, `$authType=NULL`, `$host=NULL`, `$port=22`, `$username=NULL`\n\n - `$method` can be set to `local` or `remote`, `local` will execute commands on your own shell without internet connection while `remote` executes commands on the remote server that you connect to based on your configuration.\n - `$authType` can be set to `KEY`, `PASSWORD` or `KEY_PASSWORD`, `KEY` and `KEY_PASSWORD` uses [ssh2_auth_pubkey_file](http://php.net/manual/en/function.ssh2-auth-pubkey-file.php) the difference is when you set `$authType='KEY_PASSWORD'` ssh2_auth_pubkey_file takes the last parameter of password which will now be required and `PASSWORD` uses [ssh2_auth_password](http://php.net/manual/en/function.ssh2-auth-password.php).\n - `$port` should be set to your server port if your are connecting to a remote server.\n - `$username` should be set to your server username.\n\nif your are setting connection method to `$method='remote'` and `$authType = KEY || KEY_PASSWORD` that means you will need to set your public \u0026 private key file which you can do with the setters `SSHBunny` has `$sshBunny-\u003esetKeys('public_key.pub', 'private_key')` before initialization.\n\n# Basic usage\n-------------\nThis is just going to run locally since connection method is set to `local`\n```php\n\u003c?php\n\nuse SSHBunny\\SSHBunny;\n\nrequire_once 'vendor/autoload.php';\n\n// -\u003egetData() will return output of command executed while -\u003egetData(TRUE) will dispay the output\n$sshBunny = (new SSHBunny('local'))\n    -\u003einitialize()\n    -\u003eexec(\"echo 'Hello World'\")\n    -\u003egetData(TRUE);\n```\n\nThis is going connect to a remote server since connection method is set to `remote` and authentication type is set to `KEY`\n```php\n\u003c?php\n\nuse SSHBunny\\SSHBunny;\n\nrequire_once 'vendor/autoload.php';\n\ndefined('TEST_HOST')    ? NULL : define('TEST_HOST',    \"138.222.15.1\");\ndefined('PORT')         ? NULL : define('PORT',         \"22\");\ndefined('USERNAME')     ? NULL : define('USERNAME',     \"ubuntu\");\ndefined('PUBLIC_KEY')   ? NULL : define('PUBLIC_KEY',   'id_ssl.pub');\ndefined('PRIVATE_KEY')  ? NULL : define('PRIVATE_KEY',  'id_ssl');\n\n$sshBunny = (new SSHBunny('remote', 'KEY', HOST, PORT, USERNAME))\n    -\u003esetKeys(PUBLIC_KEY, PRIVATE_KEY)\n    -\u003einitialize()\n    -\u003eexec(\"echo 'Hello World'\")\n    -\u003egetData(TRUE);\n```\n\nCommand execution can take multiple commands or you can chain on the `exec` method with another `exec` method\n```php\n$sshBunny = (new SSHBunny('remote', 'KEY', HOST, PORT, USERNAME))\n    -\u003esetKeys(PUBLIC_KEY, PRIVATE_KEY)\n    -\u003einitialize()\n    // Multiple commands\n    -\u003eexec(\"echo 'Hello World'\", \"cd /var/www/html\")\n    // Method chaining\n    -\u003eexec(\"ls -la\")\n    -\u003egetData(TRUE);\n```\n\n## Available methods\n\n- Executed command output\n```php\n// Will return the result of executed command output\n$sshBunny\n    -\u003eexec(\"ls -la\")\n    -\u003egetData();\n// Will display the result of executed command output\n$sshBunny\n    -\u003eexec(\"ls -la\")\n    -\u003egetData(TRUE);\n```\n\n- Clear stored executed command output\n```php\n// Will clear the first executed command output and return the next executed command output\n$sshBunny\n    -\u003eexec(\"ls -la\")\n    -\u003eclearData()\n    -\u003eexec(\"whoami\")\n    -\u003egetData(TRUE);\n```\n\n- Disconnect server connection\n```php\n// Will run the commands provided and display the result then disconnect from the server\n$sshBunny\n    -\u003eexec(\"ls -la\", \"whoami\")\n    -\u003egetData(TRUE)\n    -\u003edisconnect();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaraweilyas%2Fsshbunny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaraweilyas%2Fsshbunny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaraweilyas%2Fsshbunny/lists"}