I need some Jenkins jobs to have shell command line access to some other machines via ssh.
How can I do this?
I do not have the password of the target server[s], but I have a 'key' file, but when I run a job with the following
ssh -i /path/to/key/file name@someserver some_command
as a shell command, I get the following:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
ssh_askpass is a GUI utility which I nor the Jenkins user has access to.
I don't have the password to the Jenkins user (or whatever Jenkins runs as), so I cannot log in and create an ~/.ssh/id_dsa file.
What to do?
Thanks.
You need to add the public key to your user account in Jenkins. Click your username in the top-right of any page in Jenkins, click Configure in the sidebar, and there you'll find a SSH Public Key textfield to paste into.
Add SSH Key inside JenkinsIn the dropdown, select 'SSH username with private key' and then give a name for it. Copy the private key from the Jenkins server. Now you can clone any git repo in this Jenkins instance. You do not need to provide the credentials while configuring the job in Jenkins.
Ssh is asking for password either because the key is not valid or the key is protected by a passphrase.
Try the key by running the same command yourself to find out which problem you need to solve.
If the key is protected by a passphrase, you should probably remove the passphrase because there is no good way to input the passphrase in a Jenkins job. You can do it with ssh-keygen -p -f /path/to/key/file
. Set an empty passphrase to remove passphrase.
When you use ssh command in a non-interactive build job, you should probably use option -o BatchMode=yes
. You might also want to use -o StrictHostKeyChecking=no
, unless you can do the first login interactively and accept the host key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With