Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bitbucket Pipelines Fails to SSH into EC2 – Connection Timed Out

Puja Patel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 5, 2025

I'm trying to deploy code to an AWS EC2 instance from a Bitbucket Pipeline using SSH, but the SSH connection consistently fails with a timeout error.

Here's my setup ( I have removed the IP in this message for security purposes ):

  • Pipeline image: atlassian/default-image:latest

  • SSH command in pipeline:

    ssh -vvv -i ~/.ssh/key.pem -o StrictHostKeyChecking=no ec2-user@[ec2-ip].compute-1.amazonaws.com "echo 'Connection successful!'"
  • Error:

    pgsql
    CopyEdit
    debug1: Connecting to ec2-ip.compute-1.amazonaws.com [ip] port 22. debug1: connect to address [ip] port 22: Connection timed out ssh: connect to host ec2-[ip].compute-1.amazonaws.com port 22: Connection timed out

What I've done so far:

Added my SSH private key as a Bitbucket Repository Variable ($DEV_SSH_KEY)
Created a security group in AWS that allows inbound TCP on port 22 from all Bitbucket outbound IPs listed here (IPV4 outbound IPs about 24 of them). 
- Attached the security group to my EC2 instance.
- Confirmed the EC2 instance has a public IP and SSH is enabled.
- Verified the instance is running and accessible from my local machine.

Still, the connection fails from Bitbucket Pipelines. Is there something I'm missing in terms of:

  • Bitbucket's outbound IPs or network restrictions?

  • EC2 or security group setup?

  • Pipeline environment limitations (e.g., needing to use a newer SSH/OpenSSL image)?

Any insights would be much appreciated!

2 answers

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 6, 2025

Hey @Puja Patel ,

and welcome to the Community!

It seems you have opened a support ticket with us related to this issue. One of our support engineers is already working on the ticket and will provide a response soon.

We'll suggest focusing the investigation on the support ticket to avoid any confusion that may arise from discussing the same topic through multiple platforms.

Once the issue is resolved, if you feel comfortable, feel free to share the solution here to help any other users that may come across the same issue.

Thank you, @Puja Patel !
Patrik S

0 votes
Puja Patel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 5, 2025

Update: I have already added bitbucket pipelines public ssh key to my ec2 instances .ssh folder in authorized_keys file. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events