# Ansible using root user to ping

**URL:** <https://forum.ansible.com/t/ansible-using-root-user-to-ping/860>\
**Category:** Get Help\
**Tags:** ssh, rhel, ad-hoc, ansible-core\
**Created:** [September 17, 2023, 1:23pm UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860 "2023-09-17T13:23:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyush\_202](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/piyush_202/32/3318_2.png) [@piyush\_202](https://forum.ansible.com/u/piyush_202)\
**Post date:** [September 17, 2023, 1:23pm UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/1 "2023-09-17T13:23:25Z")

</div>

Hi,

I am new & started learning ansible. Installed and configured ansible on RHEL 9 EC2 instance. I have defined two instances in the hosts file and trying to ping them but I am getting an error. Seems ansible is using root as a user. How can I try to fix it ?

Just to add, I have also setup password less authentication for this by creating another user and made all possible settings in the sshd\_config file.

 ![error](https://us1.discourse-cdn.com/ansible/original/1X/20a52a645dd9da16faae5020b3f4cd5e6b6be68a.jpeg)

Thanks,  
Piyush

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [September 17, 2023, 1:47pm UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/2 "2023-09-17T13:47:29Z")

</div>

Hi Piyush,  
Ansible uses the user you have configured (see [ansible.builtin.ssh connection – connect via SSH client binary — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-remote_user)), falling back to what the SSH client chooses when you don’t supply a username.  
Also please note that the `ping` module doesn’t do a regular ping, but instead tries to connect to the host and runs a tiny module there.  
Cheers, Felix

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 18, 2023, 8:26pm UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/3 "2023-09-18T20:26:03Z")

</div>

to add to what @felixfontein is saying, you are using ad-hoc commands here (not an Ansible Playbook), so it is using your “current user” which you can see from the screenshot is `root` and has the `#`. You can set an `ansible_user` in your inventory or use the `-u` flag on the command line to set the user

---

<div class="post-metadata">

**Author:** ![Leo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leo/32/23_2.png) [@Leo](https://forum.ansible.com/u/Leo)\
**Post date:** [September 19, 2023, 2:44pm UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/4 "2023-09-19T14:44:37Z")

</div>

And adding to the above by @felixfontein and @IPvSean, also remember that RHEL 9 disabled remote `root` access through SSH by default.

The recommended way is to create a dedicated Ansible user in the remote node and use that user as mentioned above. You might also allow additional permissions through `sudo` for that user and use the Ansible `become` option in your playbooks if required.

Although it’s not recommended, if you _absolutely_ need remote `root` access through SSH, make sure you check the following [Red Hat article for enabling it in RHEL 9](https://access.redhat.com/solutions/6695971).

---

<div class="post-metadata">

**Author:** ![piyush\_202](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/piyush_202/32/3318_2.png) [@piyush\_202](https://forum.ansible.com/u/piyush_202)\
**Post date:** [September 21, 2023, 4:51am UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/5 "2023-09-21T04:51:21Z")

</div>

Thanks all, it worked !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 21, 2023, 4:51am UTC](https://forum.ansible.com/t/ansible-using-root-user-to-ping/860/6 "2023-10-21T04:51:40Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
