ansible ssh permission denied

14,794

Solution 1

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

Solution 2

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.

Share:
14,794
Vladimir Fejsov
Author by

Vladimir Fejsov

Updated on June 04, 2022

Comments

  • Vladimir Fejsov
    Vladimir Fejsov almost 2 years

    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?

  • MadPink
    MadPink almost 9 years
    I also had this problem and using ssh-copy-id for each host did the trick
  • Jonas Eicher
    Jonas Eicher about 8 years
    The configuration at /etc/ansible/ansible.cfg is one but not the only place where alternative ssh keys can be defined. When I faced this problem, the cause was in the inventory files, where individual keys to use for each host were defined.