Search code examples
jenkinsjenkins-cli

jenkins-cli not authenticating with provided ssh private key


[Help]

Description of Problem jenkins-cli not authenticating with provided ssh private key

Observed

when passing the jenkins-cli command:

java -jar ~/jenkins-cli.jar -s http://localhost:8080 -i ~/.ssh/ccdevops who-am-i

The console output is:

Authenticated as: anonymous

Authorities:

Desired

Jenkins should authenticate as the user with the matching public key in their profile

Relevant Information

  • jenkins v 2.46.3 and using the correct cli jar for the version
  • Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-78-generic x86_64)
  • only using recommend plugins
  • running on azure cloud in china east datacenter
  • azure network security group for the vm is configured to allow traffic
  • ssh key being used was created on the ubuntu machine jenkins is running on and the public key is in the users entry in the jenkins user database
  • Key was created using the instructions on the github site
  • jenkins-cli is running on the server and not from a remote host

Steps Tried Already

  • tried different keys with and without passphrases
  • tried the web address with localhost and the ip address
  • tried other jenkins-cli commands with same result
  • tried to create other users and putting an public ssh key in their profile. (no duplicate keys between users)
  • tried moving the location of the jenkins-cli jar from server root to jenkins home directory

Solution

  • You should also specify the SSH method and the user on the command line with -ssh and -user USER_NAME respectively. After that, your command would look like this:

    java -jar ~/jenkins-cli.jar -s http://localhost:8080 -i ~/.ssh/ccdevops who-am-i -ssh -user USER_NAME

    Also note that you'll need to be able to access the server via SSH as well.