1
votes

Our Jenkins instance is running on a CentOS Linux 7.3.x server. I'm trying to configure an additionnal "SSH server" in Jenkins Global settings.

Jenkins can't access my private key located at "/root/.ssh/my_private_key".

  • Jenkins version: 2.101
  • "Publish over SSH" plugin version: 1.18

Jenkins UI error : Publish over SSH > SSH Servers > SSH Server > Path to key"

No file matching: '/root/.ssh/my_private_key'

Jenkins UI error : Publish over SSH > SSH Servers > SSH Server > Test Configuration)

jenkins.plugins.publish_over.BapPublisherException: Failed to read file - filename [/root/.ssh/my_private_key] (relative to JENKINS_HOME if not absolute).
Message: [/root/.ssh/my_private_key]

Publish over SSH > SSH Servers > SSH Server

Name mytargethost

Hostname mytargethost.tld

Username remoteusername

Remote Directory /home/remoteusername

Use password authentication, or use a different key [x] (checked)

Passphrase / Password my_private_key_passphrase

Path to key /root/.ssh/my_private_key

Port 22

Timeout (ms) 300000

Other fields Blank

1
You run Jenkins as root? Why? - Thorbjørn Ravn Andersen
Hi @thorbjørn-ravn-andersen, you definitely pointed me to the right direction. Jenkins run as jenkins... - donmelchior

1 Answers

1
votes

Jenkins service being running as jenkins user, in order to configure Jenkins to connect with SSH using a private key, "Path to key" field in Jenkins global settings (Publish over SSH > SSH Servers > SSH Server) must be (relative to JENKINS_HOME):

.ssh/my_private_key

Of course, permissions on "my_private_key" must be 0600 & owner/group "jenkins:jenkins"

JENKINS_HOME=/var/lib/jenkins
chmod 0600 ${JENKINS_HOME}/.ssh/my_private_key
chown jenkins:jenkins ${JENKINS_HOME}/.ssh/my_private_key 

Real path for SSH key is: /var/lib/jenkins/.ssh/my_private_key if JENKINS_HOME=/var/lib/jenkins