{"record":{"id":"f2708858428ffcd1","repo":"phacility/phabricator","slug":"this-private-key-is-not-formatted-correctly-check","errorCode":null,"errorMessage":"This private key is not formatted correctly. Check that you have provided the complete text of a valid private key.","messagePattern":"This private key is not formatted correctly\\. Check that you have provided the complete text of a valid private key\\.","errorType":"exception","errorClass":"PhabricatorAuthSSHPrivateKeyFormatException","httpStatus":null,"severity":"error","filePath":"src/applications/auth/sshkey/PhabricatorAuthSSHPrivateKey.php","lineNumber":163,"sourceCode":"    $reason = 'unknown';\n    foreach ($patterns as $pattern => $pattern_reason) {\n      $ok = preg_match($pattern, $stderr);\n\n      if ($ok === false) {\n        throw new Exception(\n          pht(\n            'Pattern \"%s\" is not valid.',\n            $pattern));\n      }\n\n      if ($ok) {\n        $reason = $pattern_reason;\n        break;\n      }\n    }\n\n    if ($reason === $reason_format) {\n      throw new PhabricatorAuthSSHPrivateKeyFormatException(\n        pht(\n          'This private key is not formatted correctly. Check that you '.\n          'have provided the complete text of a valid private key.'));\n    }\n\n    if ($reason === $reason_passphrase) {\n      if ($passphrase) {\n        throw new PhabricatorAuthSSHPrivateKeyIncorrectPassphraseException(\n          pht(\n            'This private key requires a passphrase, but the wrong '.\n            'passphrase was provided. Check that you supplied the correct '.\n            'key and passphrase.'));\n      } else {\n        throw new PhabricatorAuthSSHPrivateKeyIncorrectPassphraseException(\n          pht(\n            'This private key requires a passphrase, but no passphrase was '.\n            'provided. Check that you supplied the correct key, or provide '.\n            'the passphrase.'));","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/sshkey/PhabricatorAuthSSHPrivateKey.php#L145-L181","documentation":"After all conclusive tests fail, PhabricatorAuthSSHPrivateKey matches ssh-keygen's stderr against known patterns. If the diagnostics match the 'format' pattern (ssh-keygen saying the key material is invalid), PhabricatorAuthSSHPrivateKeyFormatException is thrown: the key text itself is malformed, not a passphrase problem.","triggerScenarios":"newBarePrivateKey() on a truncated or corrupted private key: missing BEGIN/END lines, partial base64 body from a copy/paste, Windows mangling, a PuTTY .ppk file, or a key format the installed ssh-keygen is too old to parse.","commonSituations":"Terminal/editor copy that dropped lines of the key; PuTTY users pasting .ppk directly; clipboard tools truncating long keys; very old openssh-client builds facing newer key formats.","solutions":["Re-copy the entire key file including the '-----BEGIN ... PRIVATE KEY-----' and '-----END ... PRIVATE KEY-----' lines","If the key is a PuTTY .ppk, convert it first: puttygen key.ppk -O private-openssh -o key","Test locally with 'ssh-keygen -y -f keyfile' - if that fails on your machine, the key text is the problem","Upgrade openssh-client if it is ancient and the key uses a newer format"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Quick local sanity check before handing the key to Phabricator:\n$body = trim($raw_key_text);\nif (!preg_match('/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/', $body) ||\n    !preg_match('/-----END [A-Z0-9 ]*PRIVATE KEY-----/', $body)) {\n  // Reject before import: key text is incomplete.\n  return pht('Key must include complete BEGIN/END lines.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  $bare = $private_key->newBarePrivateKey($passphrase);\n} catch (PhabricatorAuthSSHPrivateKeyFormatException $ex) {\n  // Re-prompt: the key text itself is malformed, passphrase is irrelevant.\n  $needs_reupload = true;\n} catch (PhabricatorAuthSSHPrivateKeyException $ex) {\n  throw $ex;\n}","preventionTips":["Copy private keys with cat/scp, never by mouse-selecting in an editor","Convert PuTTY .ppk keys with puttygen before importing","Sanity-check with 'ssh-keygen -y -f keyfile' locally before uploading anywhere"],"tags":["ssh","private-key","format","phabricator"],"backgroundTag":"ssh-key-format-invalid","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}