Thursday, December 26, 2024

SSH Not working on AWS Ubuntu

 Situtaion : "I'm facing an issue on a newly updated Ubuntu 24 instance where SSH password authentication is enabled, but it's still not working. The error message shows: Permission denied (publickey) when attempting to connect via SSH (ubuntu@63.176.238.60). This issue is recurring with new AWS Ubuntu 24 instances.

AWS typically enforces key-based authentication for SSH access by default. Password authentication is disabled as a security measure. Even if you enable PasswordAuthentication in the SSH configuration, AWS’s cloud-init configuration might override it.

 

Step 1: Modify Cloud-Init Configuration

a) Cloud-init is responsible for applying the default configurations when an instance is launched.

  • Edit the cloud-init configuration file:

sudo nano /etc/cloud/cloud.cfg


b) Look for the disable_root and ssh_pwauth directives:

  • Ensure ssh_pwauth is set to true:

Save and regenerate SSH configuration:

sudo cloud-init clean
sudo cloud-init init
sudo cloud-init modules --mode config
sudo cloud-init modules --mode final

Step 2: Explicitly Enable Password Authentication

a) Ensure all necessary settings are enabled:

  • sudo nano /etc/ssh/sshd_config

b) Confirm these lines are set:

  • PasswordAuthentication yes
  • PubkeyAuthentication yes
  • PermitRootLogin yes

sudo systemctl restart sshd


Step 3: Update IAM User Data (Optional)

a) AWS might have custom IAM policies for SSH access. Update the user data to allow password authentication during instance launch:

  • Use the following in the user data section:

#cloud-config
ssh_pwauth: true
users:
  - default

b) Apply this during instance creation or via AWS Systems Manager if the instance is already running.


 

No comments:

Post a Comment

testing