Calling SSH command from Jenkins

cdugga picture cdugga · Aug 13, 2013 · Viewed 29.8k times · Source

Jenkins keeps using the default "jenkins" user when executing builds. My build requires a number of SSH calls. However these SSH calls fails with Host verification exceptions because i haven't been able connect place the public key for this user on the target server.

I don't know where the default "jenkins" user is configured and therefore cant generate the required public key to place on the target server.

Any suggestions for either;

  1. A way to force Jenkins to use a user i define
  2. A way to enable SSH for the default Jenkins user
  3. Fetch the password for the default 'jenkins' user

Ideally I would like to be able do both both any help greatly appreciated.

Solution: I was able access the default Jenkins user with an SSH request from the target server. Once i was logged in as the jenkins user i was able generate the public/private RSA keys which then allowed for password free access between servers

Answer

luka5z picture luka5z · Sep 23, 2016

Because when having numerous slave machine it could be hard to anticipate on which of them build will be executed, rather then explicitly calling ssh I highly suggest using existing Jenkins plug-ins for SSH executing a remote commands:

  • Publish Over SSH - execute SSH commands or transfer files over SCP/SFTP.
  • SSH - execute SSH commands.