Not able to deploy to new server with ssh publish, getting error

Hi Team

Trying to deploy code to new server with ssh, getting below error when i test the connection to remote server.

jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key. Message [invalid privatekey: [B@2d272efe]

In jennkins console log, i see below error:

SSH: Connecting from host [jenkins-server]
SSH: Connecting with configuration [remote server name] ...
SSH: Creating session: username [remote user], hostname [remote server], port [22]
SSH: Connecting session ...
ERROR: Exception when publishing, exception message [Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [remote server name]. Message [Auth fail]]]
[Pipeline] sshPublisher
SSH: Current build result is [FAILURE], not going to run.

copied jenkins pub key to remote server.
Anybody can give me steps on how and what to do to deploy code to new server?

Jenkins is able to deploy to other already added existing servers.

Thanks and appreciate your help on this.

Hi @devops1 ,

Can you log thanks to ssh from the Jenkins machine to the target machine?
Did you use the ssh-copy-id command?

1 Like

Hi @poddingue
Yes, i can login thro ssh from Jenkins to target machine.
manually copied public key from jenkins to target machine.
I will try ssh-copy-id command to check if that helps.
Thank you so much.

1 Like

Check your target servers auth or sshd logs. It’ll tell you what auth failure is caused by.

1 Like

Hi @halkeye ,

I’ve faced a similar issue. Currently, the situation is that I can connect to the remote server through SSH on the Jenkins server, but I can’t establish a connection through the SSH plugin’s UI in Jenkins (I’ve already uploaded the private key for the remote server to Credentials).

cat /var/logo/auth.log

Jan 24 20:59:37 ip-x-x-x-xsshd[47367]: Disconnected from authenticating user ssh-user xxxx port 46478 [preauth]
Jan 24 21:02:40 ip-xxx sshd[47385]: Invalid user jenkins from xxx port 46488
Jan 24 21:02:40 ip-xxxx sshd[47385]: error: Received disconnect from xxxx  port 46488:3: com.jcraft.jsch.JSchException: Auth fail [preauth]

same problem would have the same solution

that looks like a java error, not a sshd error, so i’m not sure what log you are looking at.

:no_mouth: ok it’s java’s fault…