phacility/phabricator · error · PhabricatorAuthSSHPrivateKeyFormatException
This private key is not formatted correctly. Check that you
Error message
This private key is not formatted correctly. Check that you have provided the complete text of a valid private key.
What it means
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.
Source
Thrown at src/applications/auth/sshkey/PhabricatorAuthSSHPrivateKey.php:163
$reason = 'unknown';
foreach ($patterns as $pattern => $pattern_reason) {
$ok = preg_match($pattern, $stderr);
if ($ok === false) {
throw new Exception(
pht(
'Pattern "%s" is not valid.',
$pattern));
}
if ($ok) {
$reason = $pattern_reason;
break;
}
}
if ($reason === $reason_format) {
throw new PhabricatorAuthSSHPrivateKeyFormatException(
pht(
'This private key is not formatted correctly. Check that you '.
'have provided the complete text of a valid private key.'));
}
if ($reason === $reason_passphrase) {
if ($passphrase) {
throw new PhabricatorAuthSSHPrivateKeyIncorrectPassphraseException(
pht(
'This private key requires a passphrase, but the wrong '.
'passphrase was provided. Check that you supplied the correct '.
'key and passphrase.'));
} else {
throw new PhabricatorAuthSSHPrivateKeyIncorrectPassphraseException(
pht(
'This private key requires a passphrase, but no passphrase was '.
'provided. Check that you supplied the correct key, or provide '.
'the passphrase.'));View on GitHub (pinned to 5720a38cfe)
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
Defensive patterns
Strategy: try-catch
Validate before calling
// Quick local sanity check before handing the key to Phabricator:
$body = trim($raw_key_text);
if (!preg_match('/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/', $body) ||
!preg_match('/-----END [A-Z0-9 ]*PRIVATE KEY-----/', $body)) {
// Reject before import: key text is incomplete.
return pht('Key must include complete BEGIN/END lines.');
} Try / catch
try {
$bare = $private_key->newBarePrivateKey($passphrase);
} catch (PhabricatorAuthSSHPrivateKeyFormatException $ex) {
// Re-prompt: the key text itself is malformed, passphrase is irrelevant.
$needs_reupload = true;
} catch (PhabricatorAuthSSHPrivateKeyException $ex) {
throw $ex;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- A passphrase was provided for this private key, but it does
- This private key requires a passphrase, but the wrong passph
- This private key requires a passphrase, but no passphrase wa
- This private key could not be opened with the provided passp
- This private key could not be opened. This might mean that t
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/f2708858428ffcd1.
Report an issue: GitHub.