Issues enabling password authentication and root login on Amazon EC2 instance

0

I followed the guide provided by Amazon to enable password authentication and root login on my Amazon EC2 instance, but I'm encountering errors when attempting to connect via SSH.

I followed these steps:

1-Updated the cloud-init configuration file (/etc/cloud/cloud.cfg) to enable root access and password login by setting disable_root: false and ssh_pwauth: true.

2-Updated the authorized_keys file to remove command prefixes and leave only the ssh-rsa statement. 3-Updated the sshd_config file (/etc/ssh/sshd_config) to enable password authentication and root login by setting PasswordAuthentication yes and PermitRootLogin yes. 4-Restarted the SSH service using sudo service sshd restart. Despite following these steps, I'm still unable to authenticate via password and root login. I keep receiving errors similar to:

ec2-user@x.x.x.x: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Hamza
posta un mese fa404 visualizzazioni
2 Risposte
1
Risposta accettata

It's not clear whether you still have this issue - your comment starts with still getting error but you've accepted @Mina Gobrial's answer.

The line debug1: No more authentication methods to try. in the ssh -v output shows that password authentication is never being tried, because its not a valid authentication method.

If the problem isn't resolved then I'd like to throw this in - which flavour of Linux is the EC2 running? As well as making the changes to /etc/ssh/sshd_config the entries may also be present in files under /etc/ssh/sshd_config.d/ and the same changes would need to be made to these.

See the accepted answer to https://repost.aws/questions/QUE9_NBn5MQ5KgpjVyyy3ISA/unable-to-login-with-username-and-password-in-redhat-machine-created-in-aws where PasswordAuthentication is present in /etc/ssh/sshd_config.d/50-cloud-init.conf on and instance provisioned with a Red Hat Linux AMI.

profile picture
ESPERTO
Steve_M
con risposta un mese fa
profile picture
ESPERTO
verificato un mese fa
  • You're absolutely correct. I've made the necessary changes following your suggestion, and now everything is working smoothly. Thank you for pointing out the specific details, and I apologize for any confusion caused by my oversight.

0

This error you are getting could be due to several reasons, and you need to check the following steps:

  • Verify no syntax errors in sshd_config. An unrecognized option or a typo could cause the SSH service to revert to default settings or ignore misconfigured directives.
  • Confirm the SSH service restarted correctly without errors.
  • Check for SELinux or firewall restrictions. Use sestatus to see SELinux status and setenforce 0 for testing (reset with setenforce 1 after). Additionally, ensure your firewall settings do not block the SSH service or specific SSH configurations.
  • Check permissions and ownership of SSH configuration files. sshd_config should be owned by root with 644 permissions.
  • Make sure there's no AllowUsers or DenyUsers directive in sshd_config blocking access.
  • Use ssh -vvv user@host for detailed error messages and check server logs in /var/log/auth.log or /var/log/secure for clues.

If this response has addressed your question, could you kindly accept the answer? It would greatly benefit the community. Thank you!

profile picture
ESPERTO
con risposta un mese fa
profile picture
ESPERTO
verificato un mese fa
  • still getting error I've checked the sshd_config ,the SG and set SELinux to permissive mode for the ec2 also I've created another account sshuser with another password still get the same error

    sudo service sshd restart ; echo $? returned 0 which means ssh service restarted succesfuly -----------OUTPUT OF ssh -vvv sshuser@x.x.x.x:------------------ debug1: Trying private key: C:\Users\akrou/.ssh/id_ed25519 debug3: no such identity: C:\Users\akrou/.ssh/id_ed25519: No such file or directory debug1: Trying private key: C:\Users\akrou/.ssh/id_ed25519_sk debug3: no such identity: C:\Users\akrou/.ssh/id_ed25519_sk: No such file or directory debug1: Trying private key: C:\Users\akrou/.ssh/id_xmss debug3: no such identity: C:\Users\akrou/.ssh/id_xmss: No such file or directory debug2: we did not send a packet, disable method debug1: No more authentication methods to try. sshuser@x.x.x.x: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

    ------------OUTPUT /var/log/secure:-------------------------- Mar 26 13:10:06 ip-172-31-43-104 sshd[14705]: Connection reset by invalid user sshuser x.x.x.x port 59174 [preauth]

    ---------------OUPUT /etc/cloud/cloud.cfg--------------------- disable_root:false mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service,_netdev', '0', '2'] resize_rootfs_tmp: /dev ssh_pwauth: true

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande