Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Unable to SSH into my EC2 instance via Pipeline

Kunal Dubey
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!
Oct 08, 2023

So, I have been struggling with this issue over the weekend and have tried everything that was available on the internet. 

The Issue: I need to SSH into my EC2 instance but I'm unable to.
Error: Permission Denied Permission denied (publickey). 

Things I've Done: 
1. Tried pasting the private public key pair that I have generated from the AWS console (.pem )
2. When the above way didn't work I tried generating the key pairs from the bitbucket pipeline console and pasted the public key in the .ssh/authorized_keys 
3. Fetched hosts and added them in my pipeline configuration 
4. tried ssh -t ( didn't work ) |
5. tried ssh - i ~./ssh/config root@ip ( didn't work ) 

- step:
name: Deploy to AWS EC2
deployment: development
- node
- sudo apt install ssh-askpass
- ssh-keyscan -t rsa >> ~/.ssh/known_hosts
- ssh $root@$ip 'sudo su && cd /home/ubuntu/scripts && sh'

Can someone please help me out here?


2 answers

0 votes
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 13, 2023

@Kunal Dubey hi. In additional to @Theodora Boudale response you could also try to follow this medium guide, where you could use one of the ssh type pipes: rsync-deploy.

To discover more ssh type pipes check the Marketplace.


Regards, Igor

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 09, 2023

Hi Kunal and welcome to the community!

The 'Permission denied' error indicates an issue with SSH authentication. Can you please follow these steps:

1. Open the repo on Bitbucket Cloud website, go to Repository settings > section PIPELINES, and select SSH keys

2. Fetch the fingerprint of the EC2 instance on that page, in the section Known hosts

If there are any errors, please let us know what error you see.

3. Generate an SSH key pair on that page by selecting the option Generate keys

4. Copy the public key to ~/.ssh/authorized_keys on the EC2 instance, for the user $root you are connecting with

5. Add the option -vvv in the ssh command in your yml as follows:

- ssh -vvv $root@$ip 'sudo su && cd /home/ubuntu/scripts && sh'

The -vvv argument will print verbose output that may give an indication of the cause of this error. Afterwards, when you run a build, please post the full output of the ssh command here (after sanitizing any private/sensitive data) so we can check any errors that may be reported.

You can also remove the ssh-keyscan command from your yml file. You are not trying to connect to Bitbucket Cloud, but even if you were, Bitbucket Cloud's host key is automatically added to known_hosts so this command is not needed.

Kind regards,

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events