10

I getting error "ERROR: Failed to run ssh-add" I am trying to ssh into remote machine so

SSH credential are set pic1 Pipeline script is calling ssh-agent pic2 On executing the job I get error below pic3

I have tried this reported bug https://issues.jenkins-ci.org/browse/JENKINS-50181 but it is not working and bug has been already resolved in latest version 1.17 which i have now. Can anyone suggest how to fix this issue.

Vivek Raj
  • 459
  • 5
  • 16

5 Answers5

15

This is just a wild guess since this could have different reasons.

But I just had this error, and my problem was that when I created the credential in Jenkins I forgot to add a linebreak at the end of the input.

...
...<all the usual content>...
...
-----END OPENSSH PRIVATE KEY-----<linebreak needed here>
peedee
  • 3,257
  • 3
  • 24
  • 42
3

I got this error when I put the SSH public key into the Jenkins credential instead of properly putting the private key.

Note that the private key is the long one that looks like this:

-----BEGIN RSA PRIVATE KEY-----
... lots of unreadable random characters for many lines ...
-----END RSA PRIVATE KEY-----
Lee Meador
  • 12,829
  • 2
  • 36
  • 42
0

I got this error when I didn't put they private key's passphrase into Jenkins.

I thought the key didn't have a passphrase because I wasn't having to enter it when using the key manually. It turns out my local keyring was automatically taking care of this.

Programster
  • 12,242
  • 9
  • 49
  • 55
0

I ran into this problem after copying the credentials.xml file from an old installation to a new one. The key appears to be stored in a hashed format in the credentials.xml file and may be the hash is unique based on the version of jenkins. I just had to find the private key on my system and then paste it in the UI along with the additional line break as suggested by @peedee

Syed Ali
  • 1,817
  • 2
  • 23
  • 44
0

I had the same issue when I tried to use OpenSSH key format in Jenkins credentials - remote session always fails with ERROR: Failed to run ssh-add.

The solution was to provide a PEM key generated with -m PEM flag. So the private key format should be: "-----BEGIN RSA PRIVATE KEY-----" instead of "-----BEGIN OPENSSH PRIVATE KEY-----" etc.

PiotrS
  • 1
  • 1