# Ansible hosts configuration using private key and sudo user

**URL:** <https://forum.ansible.com/t/ansible-hosts-configuration-using-private-key-and-sudo-user/16997>\
**Category:** Ansible Project\
**Created:** [December 9, 2014, 3:47pm UTC](https://forum.ansible.com/t/ansible-hosts-configuration-using-private-key-and-sudo-user/16997 "2014-12-09T15:47:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adithya\_Khamithkar](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Adithya\_Khamithkar](https://forum.ansible.com/u/Adithya_Khamithkar)\
**Post date:** [December 9, 2014, 3:47pm UTC](https://forum.ansible.com/t/ansible-hosts-configuration-using-private-key-and-sudo-user/16997/1 "2014-12-09T15:47:19Z")

</div>

Hi I have written a playbook for Ansible to install a few application. I am having trouble as I have to run every thing as root which is not a good idea.

So I have created a sudo user and have created a private key for authentication.

Could some one help me in defining the hosts file for this scenario.

My current hosts file is like this:

```auto
[webserver]
web-01 ansible_ssh_host=192.168.0.11 ansible_ssh_user=root

```

Thanks,

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [December 10, 2014, 1:04pm UTC](https://forum.ansible.com/t/ansible-hosts-configuration-using-private-key-and-sudo-user/16997/2 "2014-12-10T13:04:58Z")

</div>

Hello,

the ansible\_ssh\_user is the one you use for logging in via SSH, not the one you switch to when sudoing

Regards  
Mirko

---

<div class="post-metadata">

**Author:** ![Adithya\_Khamithkar](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Adithya\_Khamithkar](https://forum.ansible.com/u/Adithya_Khamithkar)\
**Post date:** [December 11, 2014, 3:22am UTC](https://forum.ansible.com/t/ansible-hosts-configuration-using-private-key-and-sudo-user/16997/3 "2014-12-11T03:22:10Z")

</div>

Thanks Mirko, But I want to login with my user name which needs a private key and execute sudo. I am not sure how do i define this on the hosts file could you please help me with this.

Thanks,
