简体   繁体   中英

Amazon EC2 instance: Server refused our key

I was working on an amazon ec2 instance for almost a week now.. I installed LAMP on my ubuntu instance then suddenly yesterday, when I try to connect via SSH on putty it gives me an error "Server refused our key" and "No supported authentication methods available (server sent: public key)

在此处输入图像描述

I am not sure what is causing this error since i did not change any settings on the aws console and on the instance itself. I was able to ssh before on the server. before I start setting up the server, I assigned an elastic IP to the instance.

I am in the process of setting up ubuntu-Wordpress on aws EC2 using a Bitnami AMI. I added SSH-based security in the last installation sted and thus downloaded a .pem private key. Trying to use putty to create a SSH-tunnel I ran into the wellknown putty login problems, both regarding username and private key. I solved them in the following way: 1) username should be "bitnami" (ec2-user is not working) 2) Using puttykey to convert the public SSH-key from .pem to .ppk (as putty demands private key in ppk format) I had to use SSH-1 (RSA) instead of the default parameter. By doing so putty gave perfect connection to the private IP of my EC2 instance. Hope this helps!

What works for me is that:

  • Stopped the ec2 instance
  • detach the volume
  • attach the volume with the old instance using the same key and was able to SSH
  • mount the volume in some temp folder
  • checked the file in the directory mount_point/home/ec2-user/.ssh/authorized_keys
    Ideally, this file needs to have our key information but for me this file was empty
  • copied the old instance authorized_keys file to the newly mounted volume
  • unmount the device
  • reattach to the original ec2 instance
  • start it and let it pass the health checks

This time it works for me. But I don't know why it doesn't have my key file information at first when the instance was launched. Check this link too https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#TroubleshootingInstancesConnectingMindTerm

I tried witch ec2-user for the longest time, until realizing that this is only valid for Amazon Linux. For the Ubuntu Server 18.04 AMI, the user is ubuntu (at least at the time of writing).

在此输入图像描述

I created a new keypair and modified the ec2 instance and rebooted, only to have it reset. I had neglected to remember that the keypair is set by Elastic Beanstalk in my case since that's how the ec2 instance is provisioned. I followed these steps to select the new keypair and connections started working: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.security.html#using-features.managing.security.keypair

The public key that is being sent by Putty to the instance is being rejected. Even though you may not have changed anything something has changed. Things to check include making sure you are logging in as the correct user, Putty is able to read the public key file, and that you are trying to log in to the correct EC2 instance. If your instance did not have an Elastic IP and your instance has been stopped and started, the instance's public IP would have changed and you are now connecting to a different instance. Confirm everything in the SSH connection is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM