These scripts demonstrate common ways to use williameggers/reactphp-ssh-server.
Install dependencies first:
composer installThen run any example from the project root:
php examples/quickstart.phpMost examples listen on 127.0.0.1:2222.
Minimal SSH server example. Accepts a shell request, prints a greeting, and closes the connection after the client sends any data.
Same basic flow as quickstart.php, but enables the built-in ConsoleLogger and also demonstrates handling exec-request.
Sets an authentication banner and echoes all channel input back to the client.
Enables password authentication.
Test credentials:
- Username:
test - Password:
abc123
Enables keyboard-interactive authentication with two prompts.
Test credentials:
- Username:
test - Password:
abc123 - One-time code:
123456
Shows how to authorize users by comparing the presented public key against a trusted key list.
Update the placeholder keys in the example before using it.
Wraps the SSH server in React\Socket\LimitingServer and allows only one concurrent connection.
Enables remote TCP forwarding and demonstrates approving tcpip-forward requests for 127.0.0.1.
Run the server:
php examples/remote-forwarding.phpOn the SSH client machine, start a local web server:
php -S 127.0.0.1:3000Open a remote forward through SSH:
ssh -p 2222 -N -R 127.0.0.1:8000:127.0.0.1:3000 test@127.0.0.1Password:
abc123
Then test from the SSH server machine:
curl http://127.0.0.1:8000Enables local TCP forwarding and demonstrates approving direct-tcpip requests only for 127.0.0.1:3000.
Run the server:
php examples/local-forwarding.phpOn the SSH server machine, start a local web server:
php -S 127.0.0.1:3000From the SSH client machine, open a local forward through SSH:
ssh -p 2222 -N -L 8000:127.0.0.1:3000 test@127.0.0.1Password:
abc123
Then test from the SSH client machine:
curl http://127.0.0.1:8000These examples are intended for local development, testing, and learning. Review the main project README.md for installation details, API usage, and the security disclaimer.