# How to solve the {"Failed to connect to the host via ssh: Permission denied (publickey,password).\\r\\n", "unreachable": true} issue

**URL:** <https://forum.ansible.com/t/how-to-solve-the-failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password-r-n-unreachable-true-issue/28353>\
**Category:** Ansible Project\
**Created:** [August 17, 2018, 2:08pm UTC](https://forum.ansible.com/t/how-to-solve-the-failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password-r-n-unreachable-true-issue/28353 "2018-08-17T14:08:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_H](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@Jim\_H](https://forum.ansible.com/u/Jim_H)\
**Post date:** [August 17, 2018, 2:08pm UTC](https://forum.ansible.com/t/how-to-solve-the-failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password-r-n-unreachable-true-issue/28353/1 "2018-08-17T14:08:35Z")

</div>

I am using Ansible to create and setup new virtual machine.

after the VM is created, if I use playbook to setup VM

**ansible-playbook config-vm.yml -i …/…/vms --extra-vars “target=10.150.200.30” --extra-vars “@password.json” --vault-password-file ~/vault-password.txt**

Then I get this error  
**UNREACHABLE! =\> {“changed”: false, “msg”: "Failed to connect to the host via ssh: Shared connection to**  **10.150.200.30**  **closed.\r\n", “unreachable”: true}**

but if I explicitly ask the password  
**ansible-playbook config-vm.yml -i …/…/vms --extra-vars “target=10.150.200.30” --ask-pass --ask-become-pass --ask-vault-pass**

it will work.

How to solve this issue, I don’t want to type the password during setup process.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 17, 2018, 3:28pm UTC](https://forum.ansible.com/t/how-to-solve-the-failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password-r-n-unreachable-true-issue/28353/2 "2018-08-17T15:28:55Z")

</div>

Don't use vault?  
The whole point of vault is to encrypt information so you need a password to access it.

---

<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:** [August 20, 2018, 4:24pm UTC](https://forum.ansible.com/t/how-to-solve-the-failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password-r-n-unreachable-true-issue/28353/3 "2018-08-20T16:24:15Z")

</div>

A convenient compromise between "authenticating every time" and  
"storing vault passwords in plain text" is the use of wrappers scripts  
that fetch the vault password from agents that run in-memory.  
So you authenticate less frequently (i.e. more convenient), and don't  
store vault passwords on disk in clear text (i.e. more secure).  
I've successfully used this approach using GnuPG and LastPass.  
LastPass has the added benefit of being able to share vault passwords  
across a team (although this requires the paid version).

Dick
