# Different SSH keys for each host.

**URL:** <https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331>\
**Category:** Ansible Project\
**Created:** [January 20, 2015, 9:36pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331 "2015-01-20T21:36:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![junkmailtrapenator](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@junkmailtrapenator](https://forum.ansible.com/u/junkmailtrapenator)\
**Post date:** [January 20, 2015, 9:36pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/1 "2015-01-20T21:36:04Z")

</div>

I know it’s possible to add **–private-key=path/to/key** to specify which ssh key you would like Ansible to use. However that assumes that each host requires the same key. Is it possible to specify that setting per host, perhaps in the inventory file or something?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 20, 2015, 9:37pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/2 "2015-01-20T21:37:40Z")

</div>

set this as a host or group var:  
ansible\_ssh\_private\_key\_file

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 20, 2015, 9:37pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/3 "2015-01-20T21:37:57Z")

</div>

Via inventory you can set ‘ansible\_ssh\_private\_key\_file’ per host. See [http://docs.ansible.com/intro\_inventory.html#list-of-behavioral-inventory-parameters](http://docs.ansible.com/intro_inventory.html#list-of-behavioral-inventory-parameters)

---

<div class="post-metadata">

**Author:** ![junkmailtrapenator](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@junkmailtrapenator](https://forum.ansible.com/u/junkmailtrapenator)\
**Post date:** [January 21, 2015, 12:38pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/4 "2015-01-21T12:38:50Z")

</div>

Thanks!

Apparently I missed that when I was reading that list.

---

<div class="post-metadata">

**Author:** ![junkmailtrapenator](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@junkmailtrapenator](https://forum.ansible.com/u/junkmailtrapenator)\
**Post date:** [January 21, 2015, 1:00pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/5 "2015-01-21T13:00:04Z")

</div>

Also is there a way to do the same thing with host\_key\_checking? I’d like to turn that off but only for a certain set of hosts (eg. dev hosts generated on the fly).

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 21, 2015, 8:19pm UTC](https://forum.ansible.com/t/different-ssh-keys-for-each-host/17331/6 "2015-01-21T20:19:12Z")

</div>

I don’t believe it’s possible to have that per host, via Ansible. But you could set it up in your ssh config. There were a few other threads in this mailing list about this topic. One would be: [https://groups.google.com/d/msg/ansible-project/8p3XWlo83ho/Q1SflaZ9dyAJ](https://groups.google.com/d/msg/ansible-project/8p3XWlo83ho/Q1SflaZ9dyAJ)
