{"record":{"id":"8676898d3bf70444","repo":"nikivdev/code","slug":"ssh-keygen-failed","errorCode":null,"errorMessage":"ssh-keygen failed","messagePattern":"ssh-keygen failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ssh_keys.rs","lineNumber":89,"sourceCode":"    );\n    let status = Command::new(\"ssh-keygen\")\n        .args([\n            \"-t\",\n            \"ed25519\",\n            \"-N\",\n            \"\",\n            \"-C\",\n            &comment,\n            \"-f\",\n            key_path.to_string_lossy().as_ref(),\n        ])\n        .stdin(Stdio::null())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run ssh-keygen\")?;\n    if !status.success() {\n        bail!(\"ssh-keygen failed\");\n    }\n\n    let private_key = fs::read_to_string(&key_path)\n        .with_context(|| format!(\"failed to read {}\", key_path.display()))?;\n    let public_key_path = key_path.with_extension(\"pub\");\n    let public_key = fs::read_to_string(&public_key_path)\n        .with_context(|| format!(\"failed to read {}\", public_key_path.display()))?;\n\n    let identity = load_or_create_sealer_identity()?;\n    let sealed = seal_private_key(private_key.as_bytes(), &identity)?;\n    let (env_private_plain, env_public, env_fingerprint) = key_env_keys(&key_name);\n    let (env_private_sealed, env_private_nonce, env_private_sealer_id) =\n        key_env_sealed_keys(&key_name);\n\n    env::set_personal_env_var(&env_private_sealed, &sealed.sealed_b64)?;\n    env::set_personal_env_var(&env_private_nonce, &sealed.nonce_b64)?;\n    env::set_personal_env_var(&env_private_sealer_id, &identity.sealer_id)?;\n    env::set_personal_env_var(&env_public, public_key.trim())?;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ssh_keys.rs#L71-L107","documentation":"setup generates an SSH keypair by invoking ssh-keygen and checking its exit status; a nonzero exit produces this terse error. Because stderr/stdout are inherited, the real reason (bad key type, weak passphrase policy, existing file with -N, no entropy) is printed directly to the terminal, but the returned error itself carries no detail.","triggerScenarios":"`ssh-keygen` invoked by setup exits nonzero: key file already exists and ssh-keygen prompts/fails in non-interactive mode, unsupported key algorithm on an old ssh-keygen, missing ssh-keygen binary handling, or invalid comment/path characters.","commonSituations":"Re-running setup when the keypair already exists; minimal Docker images or Windows environments shipping an ssh-keygen that lacks the requested key type (e.g. ed25519 on ancient OpenSSH); ssh-keygen prompting for overwrite with stdin closed (Stdio::null) causing immediate failure.","solutions":["Read the ssh-keygen output printed above the error for the actual cause","Delete or move the existing key files if setup is being re-run on the same path","Check `ssh-keygen -t ed25519` works manually to confirm key-type support and version","Pre-check key_path existence and skip generation if the keypair is already present"],"exampleFix":"// before: overwrites prompt fails with stdin null\n.stdin(Stdio::null())\n...\n// after: skip generation when keys already exist\nif !key_path.exists() {\n    let status = Command::new(\"ssh-keygen\")\n        .args([...])\n        .stdin(Stdio::null())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run ssh-keygen\")?;\n    if !status.success() { bail!(\"ssh-keygen failed\"); }\n}","handlingStrategy":"validation","validationCode":"// pre-checks before invoking ssh-keygen\nif key_path.exists() {\n    eprintln!(\"key already exists at {}, skipping generation\", key_path.display());\n} else {\n    let out = std::process::Command::new(\"ssh-keygen\")\n        .arg(\"-t\").arg(\"ed25519\").arg(\"-l\")\n        .output()?;\n    if !out.status.success() {\n        eprintln!(\"ssh-keygen missing or lacks ed25519 support\");\n    }\n}","typeGuard":null,"tryCatchPattern":"match setup(&opts) {\n    Ok(keys) => use_keys(keys),\n    Err(e) if e.to_string() == \"ssh-keygen failed\" => {\n        eprintln!(\"ssh-keygen exited nonzero — check the ssh-keygen output above for the real cause (existing file? unsupported key type?)\");\n        std::process::exit(1);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Skip key generation when the keypair already exists to stay idempotent","Verify ssh-keygen supports the requested key type (ed25519) on the target platform","Never pipe Stdio::null to stdin if ssh-keygen might prompt (e.g. overwrite)","Test `ssh-keygen -t ed25519` manually in fresh containers before automating it"],"tags":["ssh","ssh-keygen","process","key-generation"],"backgroundTag":"ssh-keygen-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}