Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up ssh for Jenkins to use at runtime

Tags:

ssh

jenkins

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.

like image 231
average guy Avatar asked Apr 07 '12 00:04

average guy


People also ask

How do I access Jenkins via ssh?

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.

How do I add ssh credentials in Jenkins?

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.


1 Answers

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.

like image 194
sti Avatar answered Sep 28 '22 11:09

sti