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:
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!
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
Update: I have already added bitbucket pipelines public ssh key to my ec2 instances .ssh folder in authorized_keys file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.