Report this

What is the reason for this report?

I am able to ping ansible nodes/target machine on aws ec2 as root but not as any user on the controller/master

Posted on April 29, 2020

e.g i create a user “student” on controller-node/master and i try this command “ansible all -m ping” its not working

i get this error:

node1 | UNREACHABLE! => { “changed”: false, “msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).”, “unreachable”: true }

node1 is target/slave machine



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.

Heya,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

The issue you’re facing seems to be related to SSH keys and permissions. When you use Ansible as a non-root user, like “student”, it uses that user’s SSH keys for connecting to the target machine.

If the user “student” does not have the right SSH key that allows access to the “node1” machine, you’ll see this Permission denied error. Check if the user “student” has the right SSH keys configured. If not, you should either add the required SSH keys for the user “student” or use the ansible_ssh_private_key_file variable in your Ansible playbook to specify the right key file.

Please make sure that the “student” user has the necessary permissions. Also, verify if the SSH authentication is configured correctly on your target machine.

For more information on how to manage SSH keys in Ansible, you can refer to the DigitalOcean tutorial.

Hope that this helps!

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.