SSH Error: Permission denied (publickey,password) in Ansible

Question:

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?

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.

I tried to connect to my VM using the host via SSH. It connected by the following command:

And I got the shell access. This means my SSH connection is working fine.

Now I tried the following command for Ansible:

And the content in the /etc/ansible/host is 10.4.1.141.

Then it shows the following error:

10.4.1.141 | FAILED => SSH Error: Permission denied (publickey,password).

while connecting to 10.4.1.141:22

It is sometimes useful to rerun the command using -vvvv, which prints SSH debug output to help diagnose the issue.

Then I tried creating the config file in .ssh/ folder on the host machine, but the error is still the same.

The content of the config file is:

which is the path to my private key.

Then I ran the same command ansible all -m ping and got the same error again.

When I tried another command,

Then it asked for the SSH password. I gave it (I am very sure the password is correct), but I got this error:

10.4.1.141 | FAILED => FAILED: Authentication failed.

This is the log using -vvvv:

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.

Answer:

I fixed the issue. The problem was in my /etc/ansible/hosts file.

The content written in /etc/ansible/hosts was 10.4.1.141. But when I changed it to rajat@10.4.1.141, then the issue got fixed.

Leave a Reply