Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Jenkins to SSH into an EC2 Instance with a private key pem file which is password protected

My aim is to execute shell commands on an EC2 instance as part of Jenkins job.

So I'm trying to SSH into an EC2 Instance with a private key pem file which is password protected from Jenkins build job, what are the ideal ways to do that?

like image 252
karthik v Avatar asked Oct 24 '25 02:10

karthik v


2 Answers

Login to jenkins

Create a "New item" or in your existing jenkins job do following

Goto "General" tab

Now under "Build>Execute shell>command"

write your command to ssh to the EC2 instance

ssh ec2-user@ 'bash -s' < script.sh

Is this helpful!!

like image 64
Micheal chores Avatar answered Oct 25 '25 17:10

Micheal chores


As suggested in the comments by burnettk, the plugin: Publish Over SSH was helpful in my scenario. I was trying to "ADD SSH Host" in Configure Section of Jenkins but got fed up with "unable to connect" message and tried Publish over SSH plugin it helped out.

like image 39
karthik v Avatar answered Oct 25 '25 18:10

karthik v