Jenkins Pipeline: SSHAgent remote ssh

in the Jenkins2.0 pipeline I need remote ssh for the target machine. My old approach was to use "Execute shell scripts on a remote host using ssh". I would like to specify both username and password.

I read that groovy approach might be something like

sshagent(['RemoteCredentials']) { sh 'ssh -o StrictHostKeyChecking=no -l remoteusername remotetarget uname -a' } 

RemoteCredentials: This is a private key with a passphrase.

Is there any way to make ssh with username / password of remote credentials? Sshagent does not support auth username / password

Riccardo

+5
source share
2 answers

Sorry, you're right.

It seems that the ssh-agent plugin only supports stored user, passphrases, public key credentials added in the credential management area in Jenkins. Take a look at unit test , which verifies that ssh-agent is working correctly based on the public key. It is unlikely that the plugin has unverified functionality to support user authentication + password.

If you can, set the switch to public key authentication. If for some reason you cannot switch ... you CAN install sshpass in your Jenkins box, but this is usually considered bad practice.

 node { stage 'Does sshpass work?' sh 'sshpass -p \'password\' ssh user@host "ls; hostname; whois google.com;"' } 
+5
source

You can link to this ssh using username / password https://jenkins.io/blog/2019/02/06/ssh-steps-for-jenkins-pipeline/ sshCommand remote: remote, command: 'for i in { fifteen}; do echo -n \ "Loop \ $ me \"; The date; sleep 1; made'

0
source

All Articles