How to easily add ssh credentials on Jenkins Server

Jenkins can make ssh connection to a remote server for the purpose of executing a command or running a script or we can also copy file from jenkins or some other server to another remote server. For this purpose, we need to create a ssh connection between Jenkins server & remote server.

This tutorials details the process to add ssh credentials on Jenkins server & easily make a ssh connection with a remote server.

Recommended Read: Complete guide for Apache TOMCAT installation on Linux

Also Read: How to install Jenkins on Tomcat : Complete Guide


Toadd ssh credentials on Jenkins server, we need to have ‘SSH Credentials’ plugin installed on jenkins server . It can be installed through ‘Manage Plugins’ section under ‘Manage Jenkins’ or we can also install it by downloading it from the following link, PUBLISH OVER SSH.
Once we have installed it, we can now add ssh credentials on jenkins servers.

For detailed instructions on how to install plugins on Jenkins server, please refer to out article “3 methods to Install Plugins on Jenkins server”

Add ssh credentials on Jenkins server

Next step in adding SSH credentials on Jenkins requires us to have the private ssh key for the server we want to connect with Jenkins server. So let’s take a scenario, we want to connect to a server from jenkins with user ‘Dan’ .
So to produce the private, login to the server as dan & goto folder ‘/home/dan/.ssh’,

$ ssh [email protected]

$ cd ~/.ssh

Next step will be to produce the public/private key for the user dan on the remote server,

$ ssh-keygen -t rsa -f for_jenkins_key

here, for_jenkins_key is the name of the keys that will be generated. There will be two files ‘for_jenkins_key’ & ‘’. We need to use the content of ‘for_jenkins_key’ in the jenkins server & the content of ‘’ file goes into another file named ‘authorised_keys’ located in the same folder i.e. .ssh folder,

$ cat > authorized_keys

Note:- authorized_keys file might not be present by default. If that’s the case, than create one.

Next copy all the content of ‘for_jenkins_key’ file & now login to your jenkins server. Once logged in, goto ‘Manage Jenkins’ & than to ‘Configure System’ or alternatively you can also visit the url ‘http://localhost:8080/configure’ to go there directly (here localhost:8080 is the jenkins location on my server, replace it with yours).

Now in ‘Configure Jenkins’ look for section that says ‘SSH Server’. Remember that this section will only appear if you have ‘SSH Credential Plugin’ installed on jenkins server.

ssh credentials on Jenkins server

As already mentioned, enter the details related to your remote machine,

ssh credentials on Jenkins server

Next click on ‘Advanced’ & check the box that says ‘Use password authentication, or use a different key’. Than enter the passphrase, if used any during the creation of ssh keys on remote machine & than paste the contents of ‘for_jenkins_key’ in the section ‘key’,

ssh credentials on Jenkins server

After making the changes, click on ‘Test Configuration’ & you should get a success message if all the settings are correct.

ssh credentials on Jenkins server

Lastly, click on ‘Save’ button at the bottom of the page & we have successfully created a ssh connection to a remote server. Now whenever we need to execute a command or need to copy files to remote server from jenkins, all we have to do is just write the command, for example ‘ssh [email protected] date’ & command will be executed on the remote machine & output will show on the jenkins console output.

I hope this tutorial on how to add ssh credentials on Jenkins server was helpful to you. Please do let us know if you are facing any issues or have any suggestions, you can use the comment box below.]

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of your hard earned money:

Linux TechLab is thankful for your continued support.


Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

7 Responses

  1. Joseph Levarato says:

    Hey, I tried to follow your step-by-step tutorial, it started really nice, but when I reach /configure, I don’t have any “SSh server” section. I have “SSH Credentials Plugin” installed by default, and I tried to install a bunch of SSH plugins, but nothing appears like in your screenshots. I’m using Jenkins v. 2.130, is there any way you could help me?

    Thank you in advance

    • Shusain says:

      Hi Joseph,
      I have also used more than one plugin to store ssh credentials on my jenkins server & all the plugins are configured using ‘Manage Jenkins’ sections only.
      Look for something like ‘SSH Server’ in ‘Manage Jenkins’ or if that still is not working for you than you can try another plugin called ‘Publish over ssh’, if you need jenkins for deployment.

      If still you face any issue, you can write to us @ [email protected]. We will certainly help you out.

  2. Abhinav bhargava says:

    Hi Shusain,

    These is a very nice and detailed tutorial here and I found it very useful. I was trying my hands on “Publish over SSH ” plugin and was not able to get a success result of Test Configuration even though I generated the SSH Key and used it in authorized key file but after reading your article I was able to configure and test the SSH Server credential configuration successfully.
    However, when I a trying to connect to the server and execute a command from my pipeline it is giving me an “Host key verification failed.” error.

    This the pipeline that I am testing.
    node {
    stage(‘Test’) {
    sh ‘hostname’
    stage(‘Run DTC PRICE data ppatch’) {
    sh ‘echo “Success!”; exit 0’
    stage(‘Execute test command over SSH remote server’){
    sh ‘ssh [email protected]_host ls -lrt’

    Could you please help in identifying what I am doing wrong here in using the SSH?

  3. Naveen Kumar Hindiganalla Munibachanna says:

    Hi Abhinav, did you resolve this issue, I am facing the same issue.

  4. suprit says:

    I am grateful for providing step by step tutorial. However, I would like to make a few suggestions.
    1. If we are using a shared server then the command ***cat > authorized_keys*** this will overwrite the authorized_keys file if it exists. It would be good to use “>>” to ensure we are appending key at the end of the file.

    2. We tested the success message on Jenkins which is awesome but to extend this tutorial you could show us an example of executing a small shell script on a remote server using Jenkins. I know it’s not the scope of this tutorial but it would be helpful for beginners to see end to end workings of Jenkins.


  5. Jeremie says:

    If that can help, i ‘ve just done this shell script on a publish over ssh build step :

    echo "index des fichiers html[generated at $(date '+%Y-%m-%d %H:%M:%S')]" >index.html && for f in *.htm; do echo $f | sed "s/^/\\/" >>index.html && grep "name=\"nom\"" $f | sed "s/.*//" | sed "s/>index.html && echo " [$f]" >>index.html; done

    creates an index of html files,
    Searches for title in
    Think can by handy

Leave a Reply

Your email address will not be published. Required fields are marked *