{"record":{"id":"e008609d907c257a","repo":"phacility/phabricator","slug":"provided-public-key-is-not-properly-formatted","errorCode":null,"errorMessage":"Provided public key is not properly formatted.","messagePattern":"Provided public key is not properly formatted\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php","lineNumber":45,"sourceCode":"    if (!strlen($entire_key)) {\n      throw new Exception(pht('No public key was provided.'));\n    }\n\n    $parts = str_replace(\"\\n\", '', $entire_key);\n\n    // The third field (the comment) can have spaces in it, so split this\n    // into a maximum of three parts.\n    $parts = preg_split('/\\s+/', $parts, 3);\n\n    if (preg_match('/private\\s*key/i', $entire_key)) {\n      // Try to give the user a better error message if it looks like\n      // they uploaded a private key.\n      throw new Exception(pht('Provide a public key, not a private key!'));\n    }\n\n    switch (count($parts)) {\n      case 1:\n        throw new Exception(\n          pht('Provided public key is not properly formatted.'));\n      case 2:\n        // Add an empty comment part.\n        $parts[] = '';\n        break;\n      case 3:\n        // This is the expected case.\n        break;\n    }\n\n    list($type, $body, $comment) = $parts;\n\n    $recognized_keys = array(\n      'ssh-dsa',\n      'ssh-dss',\n      'ssh-rsa',\n      'ssh-ed25519',\n      'ecdsa-sha2-nistp256',","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php#L27-L63","documentation":"newFromRawKey() splits the key on whitespace into at most three parts (type, body, comment). If the split yields exactly one part, there is no type/body separation at all, so the key cannot have a valid 'type base64body' shape and the generic format exception is thrown.","triggerScenarios":"Submitting a single token with no whitespace: just the base64 body without the 'ssh-rsa'/'ssh-ed25519' prefix, or a bare word/garbage string.","commonSituations":"Users copying only the base64 portion of the key and losing the algorithm prefix; terminal copy that grabbed a fragment; keys whose type prefix was edited away.","solutions":["Paste the complete one-line key starting with its type, e.g. 'ssh-ed25519 AAAAC3Nza... user@host'","Re-copy the line from the .pub file rather than reconstructing it by hand","Verify the line has at least two whitespace-separated fields before submitting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Cheap shape check before calling newFromRawKey():\n$parts = preg_split('/\\s+/', str_replace(\"\\n\", '', trim($raw)), 3);\nif (count($parts) < 2) {\n  return pht('Key must be \"<type> <base64 body> [comment]\", e.g. ssh-ed25519 AAAA...');\n}","typeGuard":null,"tryCatchPattern":"try {\n  $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($raw);\n} catch (Exception $ex) {\n  // Show 'Provided public key is not properly formatted.' on the field.\n  $e_key = $ex->getMessage();\n  $errors[] = $ex->getMessage();\n}","preventionTips":["Copy the entire single line from the .pub file - the algorithm prefix must come along","Validate client-side that the pasted line has at least two whitespace-separated fields"],"tags":["ssh","public-key","format","phabricator"],"backgroundTag":"ssh-public-key-invalid","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}