I'm generated ssh key, and copy it to remote server. When I try to ssh to that server everything works fine:
ssh user@ip_address
User is not a root. If I try to ssh throw ansible:
ansible-playbook -i hosts playbook.yml
with ansible playbook:
---
- hosts: web
remote_user: user
tasks:
- name: test connection
ping:
and hosts file:
[web]
192.168.0.103
I got error:
...
Permission denied (publickey,password)
What's the problem?
In short, Ansibles error failed to connect to the host via ssh occurs due to improper SSH configuration or incorrect Ansible Inventory file. Today, we saw how our Support Engineers fix this error.
Ansible: Permission denied (publickey, password) 34 ansible SSH connection fail 1 Ansible: Stuck at connection phase / gathering facts 2 Ansible - establishing initial SSH connection 0 google cloud - permission denied when running dynamic inventory through ansible
Need help? Our experts have had an average response time of 12.54 minutes in June 2022 to fix urgent issues. We will keep your servers stable, secure, and fast at all times for one fixed price. Receiving an error message “Ansible ssh error permission denied (password)”? We can help you in fixing it.
It connects to the hosts via SSH and pushes small programs or Ansible modules into the hosts. Ansible executes these modules and removes them when it is done.
Ansible is using different key compared to what you are using to connect to that 'web' machine.
You can explicitly configure ansible to use a specific private key by
private_key_file=/path/to/key_rsa
as mentioned in the docs Make sure that you authorize that key which ansible uses, to the remote user in remote machine with ssh-copy-id -i /path/to/key_rsa.pub user@webmachine_ip_address
In my case I got similar error while running ansible playbook when host changed it's fingerprint. I found this, trying to establish ssh connection from command line. So, after running ssh-keygen -f "/root/.ssh/known_hosts" -R my_ip
this problem was solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With