Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Teamcity SSH private key login failed: invalid privatekey

I set SSH login which connect from Windows Agent to Linux but TeamCity gives following error.

[New build problem] com.jcraft.jsch.JSchException: invalid privatekey: [B@5543cd

The keypair which generated by SSH Secure Shell has no problem to connect to server.

Similar question is here but it's not my programmatic problem but teamcity inner exception.

Note that my problem is not a case of GitHub VCS connectivity issue. just a problem between my Windows TeamCity Agent to CentOS Linux server.

Full stacktrace is as below.

[Step 6/8] com.jcraft.jsch.JSchException: invalid privatekey: [B@5543cd at com.jcraft.jsch.KeyPair.load(KeyPair.java:702) at com.jcraft.jsch.KeyPair.load(KeyPair.java:542) at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40) at com.jcraft.jsch.JSch.addIdentity(JSch.java:389) at com.jcraft.jsch.JSch.addIdentity(JSch.java:349) at jetbrains.buildServer.deployer.agent.ssh.SSHSessionProvider.initSessionKeyFile(SSHSessionProvider.java:110) at jetbrains.buildServer.deployer.agent.ssh.SSHSessionProvider.(SSHSessionProvider.java:80) at jetbrains.buildServer.deployer.agent.ssh.SSHExecRunner.createBuildProcess(SSHExecRunner.java:26) at jetbrains.buildServer.agent.impl.runner.CallRunnerService.doCreateBuildProcess(CallRunnerService.java:71) at jetbrains.buildServer.agent.impl.runner.CallRunnerService.createBuildProcess(CallRunnerService.java:47) at jetbrains.buildServer.agent.impl.buildStages.runnerStages.start.CallRunnerStage.doBuildStage(CallRunnerStage.java:47) at jetbrains.buildServer.agent.impl.buildStages.RunnerStagesExecutor$1.callStage(RunnerStagesExecutor.java:25) at jetbrains.buildServer.agent.impl.buildStages.RunnerStagesExecutor$1.callStage(RunnerStagesExecutor.java:18) at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.callRunStage(StagesExecutor.java:78) at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.doStages(StagesExecutor.java:37) at jetbrains.buildServer.agent.impl.buildStages.RunnerStagesExecutor.doStages(RunnerStagesExecutor.java:18) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.RunnerContextExecutor.callRunnerStages(RunnerContextExecutor.java:43) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.StepExecutor.processNextStep(StepExecutor.java:25) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.ForEachBuildRunnerStage.executeRunnerStep(ForEachBuildRunnerStage.java:138) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.ForEachBuildRunnerStage.runStep(ForEachBuildRunnerStage.java:123) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.ForEachBuildRunnerStage.executeBuildRunners(ForEachBuildRunnerStage.java:83) at jetbrains.buildServer.agent.impl.buildStages.startStages.steps.ForEachBuildRunnerStage.doBuildStage(ForEachBuildRunnerStage.java:44) at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(BuildStagesExecutor.java:31) at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(BuildStagesExecutor.java:24) at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.callRunStage(StagesExecutor.java:78) at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.doStages(StagesExecutor.java:37) at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor.doStages(BuildStagesExecutor.java:24) at jetbrains.buildServer.agent.impl.BuildRunAction.doStages(BuildRunAction.java:70) at jetbrains.buildServer.agent.impl.BuildRunAction.runBuild(BuildRunAction.java:50) at jetbrains.buildServer.agent.impl.BuildAgentImpl.doActualBuild(BuildAgentImpl.java:263) at jetbrains.buildServer.agent.impl.BuildAgentImpl.access$100(BuildAgentImpl.java:50) at jetbrains.buildServer.agent.impl.BuildAgentImpl$1.run(BuildAgentImpl.java:236) at java.lang.Thread.run(Thread.java:744)

like image 847
Youngjae Avatar asked Feb 20 '14 09:02

Youngjae


2 Answers

For everyone coming here searching for a solution to the "Invalid private key" on Teamcity, the solution is to generate the key with this command:

ssh-keygen -t rsa -m PEM

This is pointed out in this page of the documentation

like image 178
Joan Picornell Avatar answered Oct 23 '22 02:10

Joan Picornell


Most probably, the format of Private Key you are providing is not the one JSCH expects (i.e. OpenSSH).

Similar question and answer is provided here: JSCH - Invalid private key

like image 37
Ben Goldin Avatar answered Oct 23 '22 01:10

Ben Goldin