# Getting Permission Denied Error

**URL:** <https://forum.ansible.com/t/getting-permission-denied-error/35858>\
**Category:** Ansible Project\
**Created:** [October 13, 2021, 6:46am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858 "2021-10-13T06:46:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anirban\_Das](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Anirban\_Das](https://forum.ansible.com/u/Anirban_Das)\
**Post date:** [October 13, 2021, 6:46am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/1 "2021-10-13T06:46:55Z")

</div>

Hi All,

I’m trying to configure few ec2 instances using ansible, hence I created dynamic inventory in controller and playbook both. but I found that I need to pass private key where I’m little bit confused.

1. Does Private key refer to key which is being used for ansible purpose or ec2 launching keypair?

2. Do I need to mention that private key path inside playbook?

Please help me to get these answers.

Thanks,  
Anirban Das

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 13, 2021, 8:01am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/2 "2021-10-13T08:01:08Z")

</div>

Hard to give a useful answer without any actual code (playbooks, inventory, etc)

---

<div class="post-metadata">

**Author:** ![Anirban\_Das](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Anirban\_Das](https://forum.ansible.com/u/Anirban_Das)\
**Post date:** [October 13, 2021, 8:44am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/3 "2021-10-13T08:44:53Z")

</div>

HI,

aws\_ec2.yml --------\>\> dynamic inventory

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 13, 2021, 9:32am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/4 "2021-10-13T09:32:07Z")

</div>

and the exact error would be…?

---

<div class="post-metadata">

**Author:** ![Anirban\_Das](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Anirban\_Das](https://forum.ansible.com/u/Anirban_Das)\
**Post date:** [October 13, 2021, 9:37am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/5 "2021-10-13T09:37:56Z")

</div>

> UNREACHABLE! =\> {  
> “changed”: false,  
> “msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).”,  
> “unreachable”: true

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 13, 2021, 9:46am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/6 "2021-10-13T09:46:59Z")

</div>

This is just a regular SSH login issue.  
It depends on how your instances are configured. Do you have keys configured in AWS, are you using the userdata to provision them, etc.

---

<div class="post-metadata">

**Author:** ![Anirban\_Das](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Anirban\_Das](https://forum.ansible.com/u/Anirban_Das)\
**Post date:** [October 13, 2021, 11:51am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/7 "2021-10-13T11:51:00Z")

</div>

I have created aws ec2 instances through Terraform, so that time I have mentioned key name for ec2 launching. But yes didn’t mention ansible private key in terraform script. So in the provisioner bock I put ansible playbook command with private-key path. What else do I need to do??

you can check below terraform script and please guide me.

---

<div class="post-metadata">

**Author:** ![Sandip\_Bhattacharya](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sandip\_Bhattacharya](https://forum.ansible.com/u/Sandip_Bhattacharya)\
**Post date:** [October 14, 2021, 9:29am UTC](https://forum.ansible.com/t/getting-permission-denied-error/35858/8 "2021-10-14T09:29:22Z")

</div>

1. Confirm that the ssh key mentioned in "Keypair-01" is the one in your ssh-agent locally.  
2. Confirm that your local user exists on the remote host, and has the ssh-key in the authorized\_keys file.  
3. Confirm that you can do "ssh -i /path/to/private/key AWS\_HOST" and can log in without any problems.  
4. See if you can run 'ansible AWS\_HOST -m ping' and get a response.

These can provide clues to what is wrong.
