16

I am trying to login on ec2 instance server, but I am getting me errors like

Too many authentication failures for ubuntu,

or

Permission Denied (Public key).

when I connect to the server with ssh -i "pem_file" ec2_name@public_ip

When yesterday, I was login in server, it's worked but after exit from server and again trying to login it's giving me errors which is mentions above.

2
  • I also try to changes in etc/ssh/ssh_config file. Jun 25, 2015 at 13:20
  • 1
    Make sure you have ssh-add <private_key> first.
    – Eric
    Nov 10, 2017 at 3:28

5 Answers 5

51

So if you get this message

Too many authentication failures for ubuntu,

It's usually because you have tried too many private_keys to authenticate against the user ubuntu in your server.

You can get more info here:

https://superuser.com/questions/187779/too-many-authentication-failures-for-username

Try running this:

ssh-add -l
ssh-add -D 

You may have too many keys stored in your local ssh-agent.

If you get this:

Permission Denied (Public key).

it generally means that your public key is not in the ~ubuntu/.ssh/authorized_keys file on the server. You can actually debug by creating a snapshot of your EBS volume (if you are using EBS). Then create a new volume from the snapshot and then attach the volume to another running EC2 instance.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html

That way you can see what's in your /home/ubuntu/.ssh/ directory

1
  • 2
    in my case i used : ssh -i /path_to_local_rsa/id_rsa -o 'IdentitiesOnly yes' -i "ec2.pem" username@ip Aug 10, 2017 at 7:25
34

What eventually worked for me:

chmod 400 priv_key.pem               #or what you named it
ssh -o 'IdentitiesOnly yes' -i priv_key.pem [email protected]
1
  • 3
    with the -o 'IdentitiesOnly yes' option in place, it works. Never seen this problem before.
    – Slawomir
    Jun 8, 2020 at 13:58
6

In my case restarting my MacBook helped.

1
  • 1
    Worked for me as well. Jul 6, 2020 at 23:14
6

In my case, running

eval $(ssh-agent) 

fixed the issues.

You can get a better explanation here: https://unix.stackexchange.com/questions/351725/why-eval-the-output-of-ssh-agent

1

its ubuntu@publicip not ec2-user@publicip

1
  • Thank you Pearly, however I understood the question to be that they were getting permission denied responses. I am not critiquing the question or asking for clarification. I believe this does answer the question, as this is a very common problem with logging into ec2s. Most people presume it is always going to beec2-user@publicip, or in his case he used ec2_name@publicip whereas specifically for ubuntu machines you have to use this ubuntu@publicip. Not doing that he will get the Permission Denied (Public key) error and then eventually Too many authentication failures for ubuntu. Jun 19, 2018 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.