title: SSH Error: Permission denied (publickey,password) in Ansible
body: <p>I am new to Ansible and I am trying to implement it. I tried all the possible ways present on the Internet and also all questions related to it, but still I can't resolve the error. How can I fix it?</p>
  <p>I installed Ansible playbook on my MacBook Pro. I created a VM whose IP address is 10.4.1.141 and host IP address is 10.4.1.140.</p>
  <p>I tried to connect to my VM using the host via SSH. It connected by the following command:</p>
  <pre><code>ssh user@10.4.1.141
  </code></pre>
  <p>And I got the shell access. This means my SSH connection is working fine.</p>
  <p>Now I tried the following command for Ansible:</p>
  <pre><code>ansible all -m ping
  </code></pre>
  <p>And the content in the <code>/etc/ansible/host</code> is <code>10.4.1.141</code>.</p>
  <p>Then it shows the following error:</p>
  <blockquote>
  <p>10.4.1.141 | FAILED =&gt; SSH Error: Permission denied (publickey,password).</p>
  </blockquote>
  <blockquote>
  <p>while connecting to 10.4.1.141:22</p>
  </blockquote>
  <p>It is sometimes useful to rerun the command using <code>-vvvv</code>, which prints SSH debug output to help diagnose the issue.</p>
  <p>Then I tried creating the <code>config</code> file in <code>.ssh/</code> folder on the host machine, but the error is still the same.</p>
  <p>The content of the <code>config</code> file is:</p>
  <pre><code>  IdentityFile ~/.ssh/id_rsa
  </code></pre>
  <p>which is the path to my private key.</p>
  <p>Then I ran the same command <code>ansible all -m ping</code> and got the same error again.</p>
  <p>When I tried another command,</p>
  <pre><code>ansible all -m ping -u user --ask-pass
  </code></pre>
  <p>Then it asked for the SSH password. I gave it (I am very sure the password is correct), but I got this error:</p>
  <blockquote>
  <p>10.4.1.141 | FAILED =&gt; FAILED: Authentication failed.</p>
  </blockquote>
  <p>This is the log using <code>-vvvv</code>:</p>
  <pre><code>&lt;10.4.1.141&gt; ESTABLISH CONNECTION FOR USER: rajatg
  &lt;10.4.1.141&gt; REMOTE_MODULE ping
  &lt;10.4.1.141&gt; EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=&quot;/Users/rajatg/.ansible/cp/ansible-ssh-%h-%p-%r&quot; -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 10.4.1.141 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445512455.7-116096114788007 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1445512455.7-116096114788007 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1445512455.7-116096114788007'
  10.4.1.141 | FAILED =&gt; SSH Error: Permission denied (publickey,password).
      while connecting to 10.4.1.141:22
  It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
  </code></pre>
  <p>I am still not able to figure it out what the problem is. It is my last choice to ask it here after doing my all research. <a href="https://valdhaus.co/writings/ansible-mac-osx/" rel="noreferrer">This is the link I referred to</a>.</p>