Reputation: 20242
I want to use the Jenkins CLI, and for that I think that I need to generate an SSH key pair on my machine and put the public key of that pair in the Jenkins server configuration.
I generated an SSH key on my machine with ssh-keygen -t rsa -b 4096 -C "[email protected]"
and I'm trying to give the public key to the Jenkins server.
However, if I go to Jenkins -> Credentials -> System -> Global Credentials, the only SSH-related option is SSH Username with private key
.
Shouldn't it ask for an SSH public key instead of a private key?
Am I making any mistakes in my assumptions?
Upvotes: 2
Views: 14091
Reputation: 602
Update I just found out why the SSH Public Keys section was missing - the SSH Server plugin did not come with this version of Jenkins. After installing it, you can find the section on the User's Credentials screen as described in my original answer below.
===
I figured this out. The section Username > Security > SSH Public Keys no longer exists.
Instead, navigating to Username > Credentials (in left sidebar after navigating to user settings or clicking on the username in the right-hand corner of the screen as show in the screenshot) > click the (global) link under Domain for the current user > Add Credential (blue button at top right), then configure:
After that, just navigate to http://jenkinsurl/cli and download the CLI jar. You should be able to authenticate without a problem when you execute:
java -jar jenkins-cli.jar -s http://34.214.36.85:8080/ help
It should return a list of CLI commands you can use to control Jenkins via the CLI.
Upvotes: 0
Reputation: 111625
You need to add the public key to your user account in Jenkins.
Click your username in the top-right of any page in Jenkins, click Configure in the sidebar, and there you'll find a SSH Public Key textfield to paste into.
Upvotes: 7