Report this

What is the reason for this report?

Permission is denied while connecting to server with ansible via ssh

Posted on November 3, 2017

I’m getting the error below when I’m writing this

ansible -m ping all
host1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n",
    "unreachable": true
}

I have gone through all the steps in this tutorial and now I’m stuck at step 3. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-16-04

Any help is appreciated.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Since you can connect directly, your ansible is defaulting to a different key. Create/edit your ansible.cfg file in your playbook directory and add a line for the location of your key:

[defaults] private_key_file = /Users/username/.ssh/private_key

This error usually occurs when their is no valid public key set for the target server.

First check whether you have valid public and private key generated for the user which you are using. Keep public key in target server and private key in control server Get the path for private key and configure it in ansible.cfg file(check ansible docs for this)

Hi there! What happens if you try to connect to your server via SSH?

ssh root@your_server_ip

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.