Jenkins plugin ssh-agent showing "ERROR: Failed to run ssh-add"
Asked Answered
D

5

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.

Daw answered 22/8, 2019 at 8:24 Comment(0)
F
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>
Flambeau answered 4/12, 2019 at 10:57 Comment(5)
This also was the problem in my case.Buckboard
I've also faced with this issue! Thanks!Defoliant
This has not solved it for me which type of key was used? for example RSAVaniavanilla
Thank you so much, after hours looking around the linebreak did solve the issue for me too.Volost
Wow thank you so much. I swapped out some keys and everything stopped working. All our releases broken. Couldnt figure this out. Post your cashapp so i can send you some money lolCollins
T
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-----
Tallinn answered 21/8, 2020 at 18:23 Comment(1)
Same issue in my end.Rustication
L
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.

Limnetic answered 22/11, 2021 at 12:7 Comment(0)
E
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

Evaluate answered 7/1, 2022 at 4:25 Comment(0)
S
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.

Starinsky answered 2/2, 2023 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.