After recovering a Linux instance "PasswordAuthentication" in the /etc/ssh/sshd_config file changes from "Yes" to "No"

After recovering a Linux instance "PasswordAuthentication" in the /etc/ssh/sshd_config file changes from "Yes" to "No"

After recovering a Linux instance "PasswordAuthentication" in the /etc/ssh/sshd.config file changes from "Yes" to "No".

In order to provide secure access to launched instances,  AWS alters a single directive in the /etc/ssh/sshd_config at launch.  AWS alters this file at launch, regardless of its state on disk or backup.  This prevents any user from using PAM password login.  Only ssh public key authentication (based on the ec2-user key used to launch the instance) can take place.

Changed Directive (/etc/ssh/sshd_config)
#PasswordAuthentication yes
PasswordAuthentication no

To prevent this issue,  you can check "Enable User Data" in the Advanced Options of the Instance Recovery screen, and paste this into User Data:

#!/bin/bash
sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
systemctl restart sshd