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 )
@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
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.
Kind regards,
Theodora
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.