# Ansible unable to SSH

**URL:** <https://forum.ansible.com/t/ansible-unable-to-ssh/986>\
**Category:** Get Help\
**Tags:** ssh, rhel, ad-hoc, aws\
**Created:** [September 21, 2023, 4:50am UTC](https://forum.ansible.com/t/ansible-unable-to-ssh/986 "2023-09-21T04:50:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyush\_202](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/piyush_202/32/3318_2.png) [@piyush\_202](https://forum.ansible.com/u/piyush_202)\
**Post date:** [September 21, 2023, 4:50am UTC](https://forum.ansible.com/t/ansible-unable-to-ssh/986/1 "2023-09-21T04:50:40Z")

</div>

Hi All,

I have set up passwordless authentication on my AWS instance running on RHEL 9. After restarting my machine I could see that adhoc commands  
are not able to ping the remote hosts.

Below things I tried to check (if they changed after boot),

1. Modified the public IP addresses of the instances in /etc/ansible/hosts file.
2. Modified the public IP addresses of the instances in /etc/hosts file.
3. Tried to restart sshd service on remote hosts.
4. Checked the sudo’ers file, if user/s changed.
5. AWS Security groups have necessary permissions to allow SSH traffic.
6. Checked if 600 and 700 permissions are on .ssh & authorized keys.

As per the below snip, something broke after restart, can anyone suggest over it ?

Thanks,  
Piyush

 ![image_2023-09-21_101800218](https://us1.discourse-cdn.com/ansible/original/1X/1a7508971482acd03470dd8c06abff5cc54769c5.png)

---

<div class="post-metadata">

**Author:** ![jpmens](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jpmens/32/5543_2.png) [@jpmens](https://forum.ansible.com/u/jpmens)\
**Post date:** [September 21, 2023, 6:25am UTC](https://forum.ansible.com/t/ansible-unable-to-ssh/986/2 "2023-09-21T06:25:16Z")

</div>

It looks to me as though Ansible is using an incorrect SSH private key to login. Find your private key file and attempt a login manually:

```console
$ ssh -i privatekeyfilename -l ansible <IP-of-target>

```

Adding `-v` if required to see a bit more of what’s going on. If that works then you’ll be on the right track.

Then, with your `ansible` ad-hoc try adding four Vs `-vvvv` to see the SSH command it’s using.

---

<div class="post-metadata">

**Author:** ![piyush\_202](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/piyush_202/32/3318_2.png) [@piyush\_202](https://forum.ansible.com/u/piyush_202)\
**Post date:** [September 23, 2023, 12:47pm UTC](https://forum.ansible.com/t/ansible-unable-to-ssh/986/3 "2023-09-23T12:47:10Z")

</div>

In my case it was the user which I was not correct. But thanks for this information as well !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 23, 2023, 12:47pm UTC](https://forum.ansible.com/t/ansible-unable-to-ssh/986/4 "2023-10-23T12:47:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
