Laravel 4: Generate SSH public and private keys

Install phpseclib

  • In composer.json, add under require:
"phpseclib/phpseclib": "0.3.*"
  • run a composer update (warning: this will also update Laravel)
composer update

Generate the SSH keys

$rsa = new Crypt_RSA();
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
$k = $rsa->createKey();
 
echo $k['publickey'];
echo "\n";
echo $k['privatekey'];

Reference

Feedback