Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-17678

Connect to slave via SSH with key in a file fails whereas it works if pasted

      I have a master running with user XXX on a machine M1. I want to run a slave on machine M2 with user YYY. I have a private-public key in place between the two machines so that I can do
      [XXX@M1]$ ssh YYY@M2
      and I am connected.

      In Jenkins, I created credentials for username M2 and selected the option From the Jenkins master ~/.ssh. But when I try to connect it fails :

      [04/18/13 14:58:11] [SSH] Opening SSH connection to M2:22.
      ERROR: Failed to authenticate as YYY with credential=c2cdc4dd-cb39-4f15-8329-033933ad5621
      java.io.IOException: Publickey authentication failed.

      [04/18/13 14:58:11] [SSH] Authentication failed.
      hudson.AbortException: Authentication failed.

      Surprisingly, if I use the option Enter directly and copy paste the private key from ~/.ssh/id_dsa , then it works.

      What am I doing wrong ? is it that it takes ~/.ssh/id_rsa instead of id_dsa ?

          [JENKINS-17678] Connect to slave via SSH with key in a file fails whereas it works if pasted

          The order of preference is: id_rsa, id_dsa, identity

          https://github.com/jenkinsci/ssh-credentials-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java#L348

          So it will take ~/.ssh/id_rsa if that is present and only fall back to ~/.ssh/id_dsa if the id_rsa is missing.

          Where you have multiple keys and you need to specify explicitly one key, the recommendation is to either specify the path to the file or use copy & paste

          Stephen Connolly added a comment - The order of preference is: id_rsa, id_dsa, identity https://github.com/jenkinsci/ssh-credentials-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java#L348 So it will take ~/.ssh/id_rsa if that is present and only fall back to ~/.ssh/id_dsa if the id_rsa is missing. Where you have multiple keys and you need to specify explicitly one key, the recommendation is to either specify the path to the file or use copy & paste

          If you want to add a feature request to select an explicit one of those keys, then please open a separate ticket for the feature request. For now I don't see this as an issue as there are two valid work-arounds

          Stephen Connolly added a comment - If you want to add a feature request to select an explicit one of those keys, then please open a separate ticket for the feature request. For now I don't see this as an issue as there are two valid work-arounds

          I think it is good as it is. Maybe the only thing is to document this in the official documentation where it was not mentioned.

          Thank you very much for you help

          Barthélémy von Haller added a comment - I think it is good as it is. Maybe the only thing is to document this in the official documentation where it was not mentioned. Thank you very much for you help

          with ssh-credentials 1.0 or newer (at this point in time, 1.3 is recommended... and 1.3 of ssh-agent is also recommended) all three of the keys are added to the agent, so I think we can actually now resolve this as solved!

          Stephen Connolly added a comment - with ssh-credentials 1.0 or newer (at this point in time, 1.3 is recommended... and 1.3 of ssh-agent is also recommended) all three of the keys are added to the agent, so I think we can actually now resolve this as solved!

          Solved with credentials 1.6+, ssh-credentials 1.3+, ssh-agent 1.3+

          Stephen Connolly added a comment - Solved with credentials 1.6+, ssh-credentials 1.3+, ssh-agent 1.3+

            stephenconnolly Stephen Connolly
            barthelemy Barthélémy von Haller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: