<p>The answer is <code>Key Based SSH</code> </p>

<p>Reasons </p>

<ol>
<li>You can SSH multiple host machines using the same key or Different keys. </li>
<li>If you reboot your machine while playbook running it again SSH using your provided key so your ansible-playbook runs without occurring any errors.</li>
<li>Also, you get authentication using the appropriate user.</li>
</ol>

<p>use can use <strong>inventory.ini</strong> file </p>

<p><strong>example</strong> </p>

<pre><code>[hostMachine]
ubuntu@xx.xx.xx.xx  ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/path of your pem file

[ABCDMachine]
ABCD@xx.xx.xx.xx ansible_ssh_user=ABCD ansible_ssh_private_key_file=/path of your pem file
</code></pre>

<p><strong>Command for run ansible-playbook</strong></p>

<blockquote>
  <p>ansible-playbook -i inventory.ini main.yml</p>
</blockquote>

CC BY-SA 4.0
2020-01-04T10:47:42.107Z
2020-01-04T10:47:42.107Z
Shaha Nawaj Mulla
<p>What are the best practices to be followed wrt security when it comes to SSH authentication (password less, key based, etc.) when setting up Ansible in a new environment with 1000s of machines? Which is the best method of using passwordless SSH in an enterprise environment and why?</p>

<ansible><security>
Ansible SSH best practices
Harshdeep Koul
# Ansible SSH best practices

(Asked by: username_0 on 2019-12-15)

What are the best practices to be followed wrt security when it comes to SSH authentication (password less, key based, etc.) when setting up Ansible in a new environment with 1000s of machines? Which is the best method of using passwordless SSH in an enterprise environment and why?

**Tags:** ansible, security


---

## 1 answers

### Answer by username_1 on 2020-01-04. Score: 1

The answer is Key Based SSH 
Reasons 

You can SSH multiple host machines using the same key or Different keys. 
If you reboot your machine while playbook running it again SSH using your provided key so your ansible-playbook runs without occurring any errors.
Also, you get authentication using the appropriate user.

use can use inventory.ini file 
example 
[hostMachine]
ubuntu@xx.xx.xx.xx  ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/path of your pem file

[ABCDMachine]
ABCD@xx.xx.xx.xx ansible_ssh_user=ABCD ansible_ssh_private_key_file=/path of your pem file

Command for run ansible-playbook

ansible-playbook -i inventory.ini main.yml


---

