1

So I am working with Jenkins and I need to use the Jenkins CLI, but I cannot get the authentication figured out.

I was following their rather short description here: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI which said I need to convert my .ppk file from Putty into openssh format. They link you to this post here How to convert SSH keypairs generated using PuttyGen(Windows) into key-pairs used by ssh-agent and KeyChain(Linux) and I followed those instructions and tried with the file it generated, but I end up with a file that is a single line and looks like:

ssh-rsa [KEY]

When I use this file with the Jenkins CLI I get this error:

Exception in thread "main" java.io.IOException: Invalid PEM structure, '-----BEGIN...' missing
at com.trilead.ssh2.crypto.PEMDecoder.parsePEM(PEMDecoder.java:138)
at com.trilead.ssh2.crypto.PEMDecoder.decode(PEMDecoder.java:313)
at hudson.cli.PrivateKeyProvider.loadKey(PrivateKeyProvider.java:143)
at hudson.cli.PrivateKeyProvider.loadKey(PrivateKeyProvider.java:126)
at hudson.cli.PrivateKeyProvider.readFrom(PrivateKeyProvider.java:107)
at hudson.cli.CLI._main(CLI.java:440)
at hudson.cli.CLI.main(CLI.java:387)

I am really not familiar with ssh keys at all and have been searching around for a while with no luck. Can anyone instruct me on how to get my .ppk file into the correct format to use with the Jenkins CLI? Thanks!

Community
  • 1
  • 1
David C
  • 360
  • 1
  • 4
  • 13

1 Answers1

1

You have to generate a public SSH key on your machine and to declare this SSH key on your Jenkins server.

To generate a public key on your machine (with no passphrase):

ssh-keygen -t rsa

The default location for your public key is:

/Users/your.user/.ssh/id_rsa.pub

Copy your public SSH key (ssh-rsa XXXXXXXX your.email@domain.com).

Next, go on your Jenkins server and edit your Jenkins user information (via the top right corner, by clicking on your username).

Go to the "SSH Public Keys" section and paste your public key.

You should be able to access your Jenkins server with the CLI.

I've tested this configuration on my Jenkins server and it works.

brunolavit@MBP ~/Downloads$ java -jar jenkins-cli.jar -s http://myjenkinsserver.mydomain.com:8080/ version
1.577
Bruno Lavit
  • 9,486
  • 2
  • 27
  • 37