5

I've installed Jenkins in an Ubuntu server by following the documentation from Jenkins Install documentation and I am trying to set up Gerrit Trigger Plugin. While setting up Administrative Settings section the SSH Keyfile section always gives the error "/var/lib/jenkins/.ssh/id_rsa" is not a valid key file.

I've generated the ssh keys as the Jenkins user in the default location "/var/lib/jenkins/"

I've tried generating the keys with ssh-keygen, ssh-keygen -t rsa, ssh-keygen -t rsa -b 2048 and the keys are generated with and without a passphrase also as pem file but still shows as invalid key file.

The files are present in the "/var/lib/jenkins/.ssh/" location

jenkins@jenkins:~/.ssh$ ls -la
total 16
drwx------  2 jenkins jenkins 4096 Oct  9 14:18 .
drwxr-xr-x 17 jenkins jenkins 4096 Oct  9 14:18 ..
-rw-------  1 jenkins jenkins 2602 Oct  9 14:05 id_rsa
-rw-r--r--  1 jenkins jenkins  569 Oct  9 14:05 id_rsa.pub

I didn't find any log entries regarding this in jenkins log file also not in the web portal System Log section.

  • have you looked in the file? is the format correct? have you tried using the keys to ssh into another pc with `ssh-copy-id` ? – JoSSte Oct 09 '20 at 09:05
  • Yes, the file content seems fine and I can ssh to gerrit server by `ssh -p 29418 -i /var/lib/jenkins/.ssh/id_rsa jenkins@gerrit-domain` – Visakh Viswambaren Oct 09 '20 at 10:18

2 Answers2

9

Try to generate the key with the following command:

ssh-keygen -m PEM
0

Following are the steps worked for me.

  1. Currently my Jenkins home directory is pointing to /home/home_for_jenkins .And I need to use a different BOT user to fetch the Gerrit events.

  2. In order to achieve the above requirement, I have generated ssh keys for BOT user by using ssh-keygen -m PEM command and copied the generated keys to /home/home_for_jenkins folder and changed the permissions accordingly

jmoerdyk
  • 5,544
  • 7
  • 38
  • 49
Nishanth
  • 45
  • 2