-2

I am following an ansible tutorial and trying to run ad hoc ansible command but I am getting a permission denied error. My controller (local machine) is wsl ubuntu and the node is amazon linux 2023. I used the AWS UI to generate the access keys and I can reach my node via ssh with no issues.

The command I am trying to run is

ansible all -i inventory -m ping

but when I run it, I am getting

ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
    "unreachable": true
}

my inventory file is:

ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com

And my ansible.cfg file is:

private_key_file=~/.ssh/path/to/private/key

I've tried moving around where the put the 'private_key_file'. I've had it in the inventory file itself and also in the etc/ansible/ansible.cfg. I still get the same error. I've read that it's a permissions issue but I'm just very lost.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • 1
    The key you need on a server to connect to it should be the public key, not your private one; and it should be added to the `$HOME/.ssh/authorized_keys` of the user you want to connect with. This said, all those are server configurations issues and not programming issues, thus they do not fall under what is on-topic as described in the [help/on-topic], here. – β.εηοιτ.βε Aug 04 '23 at 07:07

1 Answers1

0

More than likely your issue is your Amazon Security group (probably default). That SG has to allow inbound traffic on port 22. https://docs.aws.amazon.com/vpc/latest/userguide/security-groups.html

If you set up the VPC (Virtual Private Cloud), then you may not have a route to the outside world. Try to log into one of your VMs via the AWS console, and see whether you can reach the outside world from that VM.

Jack
  • 5,801
  • 1
  • 15
  • 20