Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible ssh permission denied

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?

like image 723
Vladimir Fejsov Avatar asked Apr 13 '15 01:04

Vladimir Fejsov


People also ask

Why Ansible failed to connect to the host via SSH?

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.

What are the most common Ansible permissions denied?

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

How long does it take to fix Ansible SSH error permission denied?

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.

How does Ansible work with remote hosts?

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.


2 Answers

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

like image 96
Zasz Avatar answered Oct 09 '22 09:10

Zasz


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.

like image 25
pupizoid Avatar answered Oct 09 '22 08:10

pupizoid