{"record":{"id":"1b68a360e479c375","repo":"jdx/mise","slug":"no-public-key-for-the-ssh-private-key-at-expec","errorCode":null,"errorMessage":"no public key for the SSH private key at {}; expected {}","messagePattern":"no public key for the SSH private key at (.+?); expected (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/agecrypt.rs","lineNumber":298,"sourceCode":"        .map_err(|e| eyre!(\"age recipient plugin is unavailable: {e}\"))?;\n        Ok(Some(Box::new(plugin)))\n    } else {\n        Ok(None)\n    }\n}\n\n/// The public key beside an SSH private key: age cannot derive it, so the\n/// `.pub` file must exist.\npub(crate) async fn ssh_public_key_for_private(path: &Path) -> Result<String> {\n    let pub_path = path.with_extension(\"pub\");\n    if pub_path.exists() {\n        let content = file::read_to_string(&pub_path)?;\n        let trimmed = content.trim();\n        if trimmed.starts_with(\"ssh-\") {\n            return Ok(trimmed.to_string());\n        }\n    }\n    bail!(\n        \"no public key for the SSH private key at {}; expected {}\",\n        display_path(path),\n        display_path(&pub_path)\n    )\n}\n\n/// Every identity this machine has: `MISE_AGE_KEY`, the identity files\n/// named by the settings and the default `age.txt`, and the SSH keys named\n/// by the settings and the default `~/.ssh/id_ed25519` / `id_rsa`.\npub(crate) async fn load_all_identities() -> LoadedIdentities {\n    load_identities(false).await\n}\n\nasync fn load_identities(interactive: bool) -> LoadedIdentities {\n    let identity_files = get_all_identity_files().await;\n    let ssh_identity_files = get_all_ssh_identity_files();\n    let mut loaded = LoadedIdentities::default();\n    let mut plugin_sources = Vec::new();","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/agecrypt.rs#L280-L316","documentation":"When building age encryption recipients from an SSH private key, agecrypt looks for the corresponding .pub file next to it. If the public key file is missing or its content does not start with 'ssh-' (so it is not a valid OpenSSH public key), it throws this error since the public key is required to derive the recipient.","triggerScenarios":"Calling default_recipient_strings or load_ssh_recipient_from_path with a private key path (e.g. ~/.ssh/id_ed25519) whose sibling .pub file does not exist, or whose .pub file contains unexpected/non-OpenSSH content.","commonSituations":"User deleted or regenerated the key pair without keeping the .pub file; key stored with a nonstandard layout; .pub file holds a certificate or a comment-only line; pointing at a PuTTY or PEM-format key that has no ssh-* sibling.","solutions":["Generate the missing public key: run `ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pub`","Ensure the .pub file sits next to the private key with the expected name (private path + '.pub')","Verify the .pub file content starts with 'ssh-' (e.g. 'ssh-ed25519 AAAA...'); fix or regenerate it if not","Alternatively pass the public key explicitly via a supported recipient option instead of relying on derivation from the private key"],"exampleFix":"// before (missing sibling pub key)\nlet recipient = load_ssh_recipient_from_path(\"~/.ssh/id_ed25519\")?;\n// after: regenerate the pub key first\n// $ ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pub\nlet recipient = load_ssh_recipient_from_path(\"~/.ssh/id_ed25519\")?;","handlingStrategy":"validation","validationCode":"let pub_path = path.with_extension(\"pub\"); // or path + \".pub\" per convention\nif !pub_path.exists() {\n    return Err(anyhow!(\"missing public key {}; run ssh-keygen -y -f {} > {}\", pub_path.display(), path.display(), pub_path.display()));\n}","typeGuard":"fn has_ssh_pub_key(priv_path: &Path) -> bool {\n    priv_path\n        .parent()\n        .and_then(|d| std::fs::read_to_string(d.join(priv_path.file_name()?).to_string_lossy() + \".pub\").ok())\n        .map(|c| c.trim().starts_with(\"ssh-\"))\n        .unwrap_or(false)\n}","tryCatchPattern":"match load_ssh_recipient_from_path(&key_path) {\n    Ok(r) => use_recipient(r),\n    Err(e) if e.to_string().contains(\"no public key\") => regenerate_pub_key(&key_path)?,\n    Err(e) => return Err(e),\n}","preventionTips":["Always keep private keys and their .pub siblings together; never delete just the .pub file","Regenerate the .pub with `ssh-keygen -y` after key rotation","Validate the .pub starts with 'ssh-' before relying on it","Prefer explicit recipient strings when the key layout is nonstandard"],"tags":["ssh","age-encryption","missing-file"],"backgroundTag":"missing-credentials","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}