{"record":{"id":"b50957bb006f7e01","repo":"jenkinsci/jenkins","slug":"multiple-private-key-pairs-n-a-key","errorCode":null,"errorMessage":"Multiple private key pairs N/A: key","messagePattern":"Multiple private key pairs N/A: key","errorType":"exception","errorClass":"InvalidKeySpecException","httpStatus":null,"severity":"error","filePath":"cli/src/main/java/hudson/cli/PrivateKeyProvider.java","lineNumber":154,"sourceCode":"            byte[] bytes = new byte[(int) f.length()];\n            dis.readFully(bytes);\n            return new String(bytes, StandardCharsets.UTF_8);\n        } catch (InvalidPathException e) {\n            throw new IOException(e);\n        }\n    }\n\n    public static KeyPair loadKey(String pemString, String passwd) throws IOException, GeneralSecurityException {\n        Iterable<KeyPair> itr = SecurityUtils.loadKeyPairIdentities(null,\n                new PathResource(Paths.get(\"key\")),\n                new ByteArrayInputStream(pemString.getBytes(StandardCharsets.UTF_8)),\n                FilePasswordProvider.of(passwd));\n        long numLoaded = itr == null ? 0 : StreamSupport.stream(itr.spliterator(), false).count();\n        if (numLoaded <= 0) {\n            throw new InvalidKeyException(\"Unsupported private key file format: key\");\n        }\n        if (numLoaded != 1) {\n            throw new InvalidKeySpecException(\"Multiple private key pairs N/A: key\");\n        }\n        return itr.iterator().next();\n    }\n\n    private static final Logger LOGGER = Logger.getLogger(PrivateKeyProvider.class.getName());\n}\n","sourceCodeStart":136,"sourceCodeEnd":161,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/cli/src/main/java/hudson/cli/PrivateKeyProvider.java#L136-L161","documentation":"InvalidKeySpecException thrown by PrivateKeyProvider.loadKey when loadKeyPairIdentities returns more than one key pair from a single PEM input. The CLI expects exactly one private key per -i file, so multiple identities are ambiguous and rejected.","triggerScenarios":"A key file contains concatenated multiple private key blocks, or a format the SSHD parser expands into several identities.","commonSituations":"User concatenated several keys into one file; an SSH agent export; a PEM bundle containing a chain of private keys.","solutions":["Split the file so it contains exactly one private key, and pass that file via -i.","If you have several keys, pass each with its own -i flag rather than concatenating them.","Re-generate a single key if the file is an accidental concatenation."],"exampleFix":"# before: id_rsa holds two PEM blocks\njava -jar jenkins-cli.jar -i id_rsa -s http://j ...\n# after\njava -jar jenkins-cli.jar -i id_rsa_only -s http://j ...","handlingStrategy":"validation","validationCode":"// Count PEM private-key blocks; reject multi-key files up front\nlong count = pem.lines().filter(l -> l.contains(\"-----BEGIN\") && l.contains(\"PRIVATE KEY-----\")).count();\nif (count != 1) {\n    throw new IllegalArgumentException(\"Expected exactly one private key, found \" + count);\n}","typeGuard":null,"tryCatchPattern":"try {\n    PrivateKeyProvider.loadKey(pem, passwd);\n} catch (InvalidKeySpecException e) {\n    // split the file and pass keys individually with separate -i flags\n}","preventionTips":["Keep one private key per file.","Pass multiple keys as separate -i arguments rather than concatenating.","Inspect concatenated key files before reuse."],"tags":["jenkins-cli","ssh","private-key","authentication"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}