- Newest
- Most votes
- Most comments
Hi
The error message "Permission denied (publickey)" indicates that Ansible is unable to connect to your EC2 instance using SSH key-based authentication. Here are some troubleshooting steps you can try to fix the issue
Refer to this article: https://repost.aws/knowledge-center/ec2-linux-fix-permission-denied-errors
- Manual Connection: a manual SSH test is a great suggestion to diagnose the connection issue you're facing with Ansible.
Run the following command, replacing <your_pem_file> with the path to your private key file (e.g., ~/.ssh/id_rsa) and <public_dns> with the actual public DNS address of your EC2 instance:
ssh -i <your_pem_file> arjungoel1995@<public_dns>
If the connection is successful, you'll be logged into your EC2 instance. This suggests the issue might be with Ansible configuration.
- SSH Authentication:
- Verify SG group have port open
- Verify that key in your local have permission like 400 or 600
chmod 600 ssh_key
Suggestions: : Run ansible-playbook playbook.yml -vvv
to get more detailed output in the case of errors
Lastly: If you're stuck, you can temporarily allow password authentication for SSH on your EC2 instance (not recommended for production due to security risks). This will help you verify if the issue lies with key-based authentication.
Does the user arjungoel1995
exist on the EC2 instance (I'm guessing that's the host 18.212.22.48 ?).
If it's a different username on the target, e.g. the default ec2-user
then you need to add -u ec2-user
to the ansible-playbook
command.
If the usernames are all correct then troubelshoot this as an SSH problem (because that's what it is) and not an Ansible problem. Once you can do passwordless SSH from your local machine to the EC2 instance then it should work with Ansible as well.
Relevant content
- Accepted Answerasked a month ago
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 months ago