# how to connect via ssh to different ansible nodes that have different root credentials ?

**URL:** <https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320>\
**Category:** Ansible Project\
**Created:** [December 11, 2020, 4:15pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320 "2020-12-11T16:15:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaHwF\_Sk](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@LaHwF\_Sk](https://forum.ansible.com/u/LaHwF_Sk)\
**Post date:** [December 11, 2020, 4:15pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/1 "2020-12-11T16:15:56Z")

</div>

When configuring nodes with **Ansible** , each server has a its own user and password, but it asks for root pass for **ssh** connection.  
is it a good idea to give all servers same root pass for easy use?  
if not please how can i give each server different root pass and connect via ssh to use same playbook simultaneously in all nodes ?  
i am new to **devops** and _ **ansible** _ so please bear with me 🙂

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 11, 2020, 4:33pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/2 "2020-12-11T16:33:22Z")

</div>

It shouldn’t need root for SSH,

You should ideally have a dedicated ansible user with SSH keys.

Interested to see if anyone else has a better way of doing this though.

Option 1:

SSH keys to each server,  
Passwordless sudo for the ansible user on each host.

Option 2:

Host vars file for each host that is encrypted.

[https://docs.ansible.com/ansible/latest/user\_guide/vault.html#vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html#vault)

something like this in your playbook.

host\_vars

-host1

– vars

– vars\_creds

-host2

You have you host vars,

A directory per host and files with vars e.g. in “vars” hostname/ip/ port, etc and encrypt vars\_creds that contains your user/pass.

Option 3: (not recommended)

Host vars but without the encryption with vault.

---

<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:** [December 11, 2020, 4:45pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/3 "2020-12-11T16:45:43Z")

</div>

That should be the default choice for almost everyone.  
Only deviating from that if there are very compelling reasons to do so.  
I have not come across them, but I'm interested to know what those might be.

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 11, 2020, 5:14pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/4 "2020-12-11T17:14:35Z")

</div>

Deviates for managing windows servers  
Which is where having encrypted host\_vars helps I guess.

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 11, 2020, 5:17pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/5 "2020-12-11T17:17:59Z")

</div>

And I guess there could be an argument made against having password less sudo for a user

---

<div class="post-metadata">

**Author:** ![LaHwF\_Sk](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@LaHwF\_Sk](https://forum.ansible.com/u/LaHwF_Sk)\
**Post date:** [December 12, 2020, 2:27pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/6 "2020-12-12T14:27:09Z")

</div>

thanks so much for helping guys  
dont you think Passwordless sudo for the ansible user on each host is risky ?  
otherwise i will try to apply your second method @Stu with vars file, i think is more secure

---

<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:** [December 14, 2020, 4:58pm UTC](https://forum.ansible.com/t/how-to-connect-via-ssh-to-different-ansible-nodes-that-have-different-root-credentials/34320/7 "2020-12-14T16:58:02Z")

</div>

though i would do as previous posters suggest, the way to do what you  
initially asked for can be done with setting ansible\_user and  
ansible\_password variables per host (i recommend using vault for the  
latter).
