1. Go to this page and download the library: Download zpm-packages/server-access library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zpm-packages / server-access example snippets
use ZPMPackages\SshManager\Repositories\InMemorySshRepository;
$repository = new InMemorySshRepository();
use ZPMPackages\SshManager\Factories\SshManagerFactory;
// Detect OS automatically and create a manager for it:
$manager = SshManagerFactory::make($repository);
// This will:
// 1) Resolve the system user's home dir.
// 2) Create ~/.ssh if it doesn't exist.
// 3) Run ssh-keygen and create files (e.g. id_ed25519 and id_ed25519.pub).
// 4) Create a SshEntryEntity for this key.
// 5) Store it in the repository.
// 6) Call sync() on the provider.
$newEntry = $manager->generateKeyPairForUser(
systemUsername: 'deploy',
label: 'deploy@my-server', // comment in the key
keyType: 'ed25519', // or 'rsa'
bits: null // for rsa you can pass e.g. 4096
);
echo $newEntry->getUsername() . PHP_EOL;
echo $newEntry->getPublicKeyPath() . PHP_EOL;
echo $newEntry->getPrivateKeyPath() . PHP_EOL;