I did this as part of my project, but realized it is one of the most convoluted topics which was not discussed properly in any forum in internet. So here it is for anyone to get benefited from a similar requirement.

Prerequisite to understanding this blog:

  1. You have Jenkins installed in your windows machine.
  2. You have git bash installed in your machine.
  3. You know some basic linux commands.

You can find tons of material in the internet to install jenkins and git bash, so go ahead and do it if you don’t have it already.

Step 1: Setup the shell application in jenkins.

Login to Jenkins as administrator , or a user with authority to manage jenkins. Navigate to:

Manage Jenkins > Configure System > Scroll down to Shell

Assuming that you have downloaded GIT BASH, you should find sh.exe under C:\Program Files\Git\bin\sh.exe , now paste that in your shell executable as below:

Go ahead , save it.

Step 2: Create your ssh key and copy it to the remote linux server

  1. Open you git bash terminal.
  2. Type this : ssh-keygen -t rsa -b 2048

3. Copy the ssh key into the remote linux server

ssh-copy-id User@YOUR-REMOTE-SERVER

User@YOUR-REMOTE-SERVER’s password: **********

After the successful copy , you will get this message:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘User@YOUR-REMOTE-SERVER'” and check to make sure that only the key(s) you wanted were added.

Step 3: Go to Jenkins and create a new Job.

  1. Create a simple freestyle project in Jenkins
  2. In the build section, you can write the below:
ssh into remote linux server, cd to a directory, and list

3. Now click “Build Now” and look at your console output

That’s it, If your company is using Jenkins in windows, but you need to automate stuff in linux, this would be a great way to do it.

I would love to see a comment or like from you if you liked the blog.

Happy reading!!

One thought on “Steps to enable Jenkins in windows to ssh into remote linux server”

Leave a Reply

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