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

The previous solutions didn't work for me, unfortunately (DevOps layman here!).

But the below one worked for me.

Change your inventory file to:

[webserver] 10.4.1.141 ansible_user=ubuntu

ansible webserver --private-key pem_file.pem -m ping

Hitting the command with -vvvv helped me to debug it more.

Reference: Failed to connect to the host via ssh: Permission denied (publickey,password) #19584


If you log in with ssh [email protected]:

Option 1

Then make sure that in your hosts file inside etc\ansible you have:

[server01]
10.4.1.141

Then within etc\ansible run:

ansible all -m ping -u user --ask-pass

Option 2

If you want to log in without typing the SSH password then in your hosts file inside etc\ansible you add:

[server01]
10.4.1.141 ansible_ssh_pass=xxx ansible_ssh_user=user

Then within etc\ansible run:

ansible all -m ping

For me it worked both ways.


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 [email protected], then the issue got fixed.


My case is I have multiple private keys in my .ssh.

Here is how I fix it by telling ansible to use a certain private key

ansible-playbook -i ../../inventory.ini --private-key=~/.ssh/id_rsa_ansiadmin update.yml 

Tags:

Ssh

Ansible