You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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 )
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 deployment.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.