{"record":{"id":"6106189a3f2c6260","repo":"phacility/phabricator","slug":"can-not-generate-keys-unable-to-find-s-in-path","errorCode":null,"errorMessage":"Can not generate keys: unable to find \"%s\" in PATH!","messagePattern":"Can not generate keys: unable to find \"(.+?)\" in PATH!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/util/PhabricatorSSHKeyGenerator.php","lineNumber":8,"sourceCode":"<?php\n\nfinal class PhabricatorSSHKeyGenerator extends Phobject {\n\n  public static function assertCanGenerateKeypair() {\n    $binary = 'ssh-keygen';\n    if (!Filesystem::resolveBinary($binary)) {\n      throw new Exception(\n        pht(\n          'Can not generate keys: unable to find \"%s\" in PATH!',\n          $binary));\n    }\n  }\n\n  public static function generateKeypair() {\n    self::assertCanGenerateKeypair();\n\n    $tempfile = new TempFile();\n    $keyfile = dirname($tempfile).DIRECTORY_SEPARATOR.'keytext';\n\n    execx(\n      'ssh-keygen -t rsa -N %s -f %s',\n      '',\n      $keyfile);\n\n    $public_key = Filesystem::readFile($keyfile.'.pub');","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/util/PhabricatorSSHKeyGenerator.php#L1-L26","documentation":"Phabricator generates SSH keypairs for users (Settings → SSH Public Keys → Generate Key) by shelling out to the 'ssh-keygen' binary. assertCanGenerateKeypair() first checks that the binary is resolvable in the web-server/daemon process's PATH via Filesystem::resolveBinary(), and throws this exception when it is not found. It is an environment/setup problem, not a code problem.","triggerScenarios":"A user clicks 'Generate Key' in Settings → SSH Public Keys, or any code path calls PhabricatorSSHKeyGenerator::generateKeypair(), on a host where the PHP process cannot find 'ssh-keygen' — typically because openssh-client is not installed or the web server's PATH is minimal (e.g. /usr/bin:/bin missing, chroot, systemd service with restricted PATH).","commonSituations":"New Phabricator install where openssh-client was never installed; PHP-FPM pool with a stripped-down PATH; running under a container or chroot that omits ssh-keygen; Phacility/daemon hosts provisioned without SSH tooling.","solutions":["Install openssh-client on the host that runs PHP: 'apt-get install openssh-client' (Debian/Ubuntu) or 'yum install openssh-clients' (RHEL/CentOS).","Verify the PHP process itself can find it: 'sudo -u www-data php -r \\\"echo Filesystem::resolveBinary('ssh-keygen');\\\"' or check 'ssh-keygen' is in /usr/bin and that directory is in the pool's PATH.","Restart PHP-FPM / the web server after installing so the new PATH takes effect.","Alternatively let users upload existing public keys instead of using key generation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Probe key generation ability ahead of the UI flow and degrade gracefully:\n$can_generate = false;\ntry {\n  PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();\n  $can_generate = true;\n} catch (Exception $e) {\n  // ssh-keygen unavailable; hide the 'Generate Key' action\n}\n// Use $can_generate to decide whether to render the generate-key button.","typeGuard":null,"tryCatchPattern":"// Catch around the generation call and surface a setup message instead of a stack trace:\ntry {\n  $result = PhabricatorSSHKeyGenerator::generateKeypair();\n} catch (Exception $e) {\n  if (strpos($e->getMessage(), 'ssh-keygen') !== false) {\n    return $this->newDialog()->setTitle(pht('SSH Keygen Unavailable'))\n      ->appendParagraph(pht('Install openssh-client on the web host.'));\n  }\n  throw $e;\n}","preventionTips":["Install openssh-client on every host that runs PHP before enabling SSH key features.","Smoke-test with 'sudo -u <web-user> which ssh-keygen' after provisioning or container rebuilds.","If key generation is optional in your workflow, offer public-key upload as the fallback path."],"tags":["phabricator","ssh-keys","missing-binary","environment","php"],"backgroundTag":"executable-not-in-path","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}