# Use password protected private key for an ansible script

**URL:** <https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557>\
**Category:** Ansible Project\
**Created:** [September 12, 2018, 10:57am UTC](https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557 "2018-09-12T10:57:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madushan\_Chathuranga](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Madushan\_Chathuranga](https://forum.ansible.com/u/Madushan_Chathuranga)\
**Post date:** [September 12, 2018, 10:57am UTC](https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557/1 "2018-09-12T10:57:47Z")

</div>

Hi All,

Is it possible to provide the password of the private key on the command line extra vars or using the inventory. In the inventory we can provide the private key but not the password? can not use --ask-pass in the command since it would prompt for the password to be user provided. Needs to pass this password along with the private key. using this to execute an ansible script on a remote host.

Thanks.

---

<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:** [September 12, 2018, 12:39pm UTC](https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557/2 "2018-09-12T12:39:18Z")

</div>

Is this private key supposed to be used for connecting to a host  
you're configuring (i.e. the password to a protected SSH key)?  
Or is it used inside a task, to executed on a remote host (i.e.  
\*after\* you've connected to it)?

Dick

---

<div class="post-metadata">

**Author:** ![Madushan\_Chathuranga](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Madushan\_Chathuranga](https://forum.ansible.com/u/Madushan_Chathuranga)\
**Post date:** [September 12, 2018, 12:45pm UTC](https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557/3 "2018-09-12T12:45:58Z")

</div>

Hi,

This is to connect to the remote host. I’m aware that we can do something similar to this,

`ansible-playbook -i hosts.yml --private-key=private_key_path ansible_script.yml`

also, I know we can use the private key in the inventory host\_vars as ansible\_ssh\_private\_key  
but why ansible doesn’t provide a option to manage private\_key’s password if it allows to use a private\_key.

---

<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:** [September 13, 2018, 4:48pm UTC](https://forum.ansible.com/t/use-password-protected-private-key-for-an-ansible-script/28557/4 "2018-09-13T16:48:51Z")

</div>

I'm speculating here, but I think it's because providing passwords  
directly to ansible on the command line is more insecure than  
necessary.  
All password/authentication invocations (private keys, vault  
passwords, password prompts) seem to be done either through a prompt,  
or by pointing to a file containing the password.  
So instead of supplying a password on the command line to use an  
encrypted private key, you are encouraged to use a non-encrypted  
private key.

Again, this is my guess...

Dick
