2

When I am doing ssh to a remote windows machine from the linux CLI running the following command it works:

ssh -tt username@ip_address

However when I am running the same via Jenkins, it throws the following error:

+ ssh -tt username@ip_address
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password,keyboard-interactive)

So what could be going wrong? I believe this has nothing to do with the ssh-keys because manually running the above command from the CLI works but fails only from the Jenkins.

I am new to Jenkins and hence don't have much idea about the details of Jenkins. Please share what could be going wrong.

Thanks.

RDX
  • 145
  • 3
  • 12

1 Answers1

2

First, check with which account Jenkins is running: if it is not the same as the one used for your ssh test in command-line, it would not access the same ~/.ssh/id_rsa private key.

Second, try and specify the same key (assuming no passphrase) to the SSH plugin configuration or the SSH pipeline step, to make sure it uses the right file.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • First option is correct. In both cases, I am using the user "jenkins". Coming to the second option, I referred " SSH plugin configuration" link and found I've not configured "Execute shell script on remote host using ssh" and rest seen to be same. So is it necessary to configure "Execute shell script on remote host using ssh" section in my case? I have written my commands under the "Execute shell" section. Is it ok? – RDX Feb 08 '21 at 12:14
  • @RDX I would prefer using the SSH specific command rather than the generic execute shell option. – VonC Feb 08 '21 at 12:15
  • So in that case whatever I was writing in the generic execute shell option, same thing can I run under "Execute shell script on remote host using ssh"? If yes, then it should be under "Post build script" or "Pre build script" ? Please advise. – RDX Feb 08 '21 at 12:49
  • @RDX Prebuild, provided you did register the SSH host, with the right keyfile first (as in here: https://stackoverflow.com/a/57491006/6309): see https://www.programmersought.com/article/4529149388/ for an example. Activate verbose output, for more clues: http://joshuaayson.com/execute-ssh-command-as-root-from-a-jenkins-build-without-using-keys/ – VonC Feb 08 '21 at 13:05