Unable to configure Jenkin controller and agent in VM

I have two VMs (Ubuntu) configured on Oracle Virtual Box. I need to set up Jenkin controller (VM1) with Jenkin agent (VM2) to execute set of tasks. Connection is failing with the below exception. Request you to please suggest.

SSHLauncher{host=‘’, port=22, credentialsId=‘jenkins-agent’, jvmOptions=‘’, javaPath=‘’, prefixStartSlaveCmd=‘’, suffixStartSlaveCmd=‘’, launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[04/05/24 02:13:53] [SSH] Opening SSH connection to
[04/05/24 02:13:53] [SSH] WARNING: SSH Host Keys are not being verified. Man-in-the-middle attacks may be possible against this connection.
ERROR: Server rejected the 1 private key(s) for root (credentialId:jenkins-agent/method:publickey)
ERROR: Failed to authenticate as root with credential=jenkins-agent
java.io.IOException: Publickey authentication failed.
at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:349)
at com.trilead.ssh2.Connection.authenticateWithPublicKey(Connection.java:472)
at com.cloudbees.jenkins.plugins.sshcredentials.impl.TrileadSSHPublicKeyAuthenticator.doAuthenticate(TrileadSSHPublicKeyAuthenticator.java:110)
at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(SSHAuthenticator.java:431)
at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(SSHAuthenticator.java:468)
at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:882)
at hudson.plugins.sshslaves.SSHLauncher.lambda$launch$0(SSHLauncher.java:441)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.io.IOException: Could not generate signature
at com.trilead.ssh2.signature.KeyAlgorithm.generateSignature(KeyAlgorithm.java:43)
at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:316)
… 10 more
Caused by: java.security.SignatureException: Could not sign data
at java.base/sun.security.rsa.RSASignature.engineSign(RSASignature.java:197)
at java.base/java.security.Signature$Delegate.engineSign(Signature.java:1423)
at java.base/java.security.Signature.sign(Signature.java:712)
at com.trilead.ssh2.signature.KeyAlgorithm.generateSignature(KeyAlgorithm.java:41)
… 11 more
Caused by: javax.crypto.BadPaddingException: RSA private key operation failed
at java.base/sun.security.rsa.RSACore.crtCrypt(RSACore.java:209)
at java.base/sun.security.rsa.RSACore.rsa(RSACore.java:130)
at java.base/sun.security.rsa.RSASignature.engineSign(RSASignature.java:194)
… 14 more
[04/05/24 02:13:53] [SSH] Authentication failed.
Authentication failed.
[04/05/24 02:13:53] Launch failed - cleaning up connection
[04/05/24 02:13:53] [SSH] Connection closed.

Looks like your private key is not matching what is on the other machine. Also, please use Controller and Agent instead of the deprecated terms.

1 Like

Thanks for responding, what should i do now to match private key.

Here are a few steps that could help to fix the issue:

  1. Make sure that the SSH key pair is correctly generated. You can generate a new SSH key pair using the ssh-keygen command on a Unix-based system or using a tool like PuTTYgen on Windows.
  2. Add the public key part of the SSH key pair to the ~/.ssh/authorized_keys file of the user you are trying to connect as on the Jenkins agent.
  3. Add the private key part of the SSH key pair to the Jenkins credentials with the ID jenkins-agent for example.
  4. Double-check that the user you are trying to connect as has the correct permissions on the Jenkins agent.
  5. Try to manually SSH from the Jenkins controller to the Jenkins agent using the SSH key pair to ensure that the connection works correctly.
  6. In the Jenkins UI, change the key in the node configuration so it uses your newly created key.