"Server Refused our key" after launching instance from private EBS AMI

45,360

Solution 1

I had a similar problem with that error message and here is how I fixed it. Hope this helps you, or someone else who is stuck and finds their way here:

  1. In the AWS Console ensure your instance is healthy and running
  2. Check you have used the correct public DNS address, listed when you click on an instance
  3. Select Security Groups from left hand side and click on the security group you want to use
  4. Click the Inbound tab
  5. From the Create a new rule: dialog select SSH
  6. In source put your IP address and CIDR value. If its just you don't have a NAT on your network just use 32 as your CIDR (eg. ?.?.?.?/32)
  7. Click Add Rule
  8. Click Apply Rule Changes
  9. Right click on your instance and select Create Image (EBS AMI)
  10. Give it an Image Name in the Create Image wizard and click Create
  11. After a short time select AMI's from the left hand nav bar in AWS console
  12. Right click on the new AMI and click Launch Instance
  13. On the Request Instances Wizard click Continue until you have to Create Key Pair
  14. Choose a key pair and make note of it (NOTE: If you haven't still got your .pem file for this key pair you will need to generate a new one from selecting Key Pairs on left hand navbar, Create Key Pair etc. to obtain .pem file)
  15. Select security group with the rule you created for your IP address (and CIDR of 32 - no subnet mask)
  16. Click continue, and on the next screen click Launch
  17. Go back to the Instances view and wait until your Instance is fully initialized and healthy
  18. Open PuttyGEN
  19. Click Conversions from the Toolbar, and Import Key
  20. Navigate to your .pem key in the file browser and open it
  21. Select SSH-1 (RSA) from the Parameters box
  22. Put your key pair name in the Key comment box (just for good house keeping)
  23. Click Save private key and save the .ppk file somewhere on your file system
  24. Open Putty
  25. Enter the public DNS for your EC2 instance in the Host Name box
  26. Enter port 22
  27. Tick SSH radio button from the Connection Type box
  28. Click on SSH from the Connection tree in the left hand side nav bar
  29. Click on Auth
  30. Click Browse in the Authentication parameters box, and open your .ppk file
  31. Click Session from the left hand nav bar
  32. Enter a name for this connection in the Saved Sessions text box, and click Save (this is so you don't have to go through the putty connection set up each time, and can just double click your saved connection - for those unaware)
  33. Click Open
  34. When prompted for a login name you will probably use 'ec2-user' or 'ubuntu' (TIP: use 'root' and you will probably get a message telling you what username you should use instead!)
  35. No need for a password, the .ppk file will authenticate you
  36. Hopefully, you're now connected to the EC-2 instance and good to go!

Solution 2

I had this issue with a new SUSE instance. I was finally able to connect using user 'root'. It kept rejecting ec2-user.

Solution 3

this means that you are not using correct user name for logging into your ec2 instance. here is list of users you can use in putty to connect to ec2 instance For an Amazon Linux AMI, the user name is ec2-user. For a RHEL5 AMI, the user name is either root or ec2-user. For an Ubuntu AMI, the user name is ubuntu. For a Fedora AMI, the user name is either fedora or ec2-user. For SUSE Linux, the user name is either root or ec2-user. Otherwise, if ec2-user and root don't work, check with the AMI provider.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#TroubleshootingInstancesConnectingPuTTY

Solution 4

Since your AMI originates from a community AMI and not an official public AMI, it is possible that it has not been setup to copy the ssh keys on instance startup, or that it uses a different mechanism to do it.

My understanding is that for the ssh keys to be copied on startup, some shell script must be run inside the instance itself, as briefly described here.

The AMI description page mentions that it has been "cloud-init enabled", so maybe there is a way to do it through CloudInit. See the doc here.

Solution 5

I had this issue and it turned out I was typing ec2_user when it was meant to be ec2-user

Share:
45,360
Kelvin
Author by

Kelvin

Updated on April 26, 2021

Comments

  • Kelvin
    Kelvin about 3 years

    I have created my own EBS AMI, shared it with another AWS account, launched NEW instance based on this image with NEW key-pair and now when I am trying to connect to this new instance I am getting error: "Server Refused our key".

    This is what I did (step by step):

    1. Configured new CentOS 6.3 server in my personal account (with my personal key-pair)
    2. Created EBS AMI image of that server
    3. Shared this image with my client's account
    4. Launched new instance in my clients account based on this shared image + new key-pair
    5. New launched instance doesnt want to take new key-pair. After some testing I figure that it accepts my personal key-pair instead.

    How do I make new instance from my image to accept new key-pairs? I even tried removing ".ssh/authorized_keys" file in original image, launch new instance based on this image without public key and still no success.

    Please advise how to create images that would not be attached to old key-pairs

  • Kelvin
    Kelvin almost 12 years
    Ok, Thanks a lot for your help David. I will try to figure out what else can be done.
  • Mikael Call
    Mikael Call over 10 years
    "TIP: use 'root' and you will probably get a message telling you what username you should use instead!" - very creative!
  • s_h
    s_h over 10 years
    great, ec2-user was the user.
  • detour
    detour about 10 years
    Found this to be a helpful answer. I chose the Ubuntu 12.04 image and had to login using the ubuntu user instead of ec2-user.
  • Joseph Casey
    Joseph Casey over 9 years
    literally the best troubleshoot steps on the internet.
  • Darius
    Darius over 9 years
    You're too kind! Glad it helped!
  • markmnl
    markmnl over 8 years
    I think you can remove " If its just you don't have a NAT on your network just use 32 as your CIDR (eg. ?.?.?.?/32)" that doesnt make sense - whether you are behind NAT or not it only matters what public IP you are coming from is of which there will be only one
  • markmnl
    markmnl over 8 years
    Also creating the Image was just for prudence? It doesn't have anything to do with SSH does it? Otherwise, thanks!
  • Tonio Liebrand
    Tonio Liebrand about 7 years
    am i the only one for whom this unfortun. doesnt work?
  • Shiv Singh
    Shiv Singh over 6 years
    i am sure your combination is not correct or you are not using correct Key pair
  • MikeKulls
    MikeKulls almost 6 years
    This was actually the correct answer for me, I was typing ec2_user instead of ec2-user. So the down vote is a bit harsh.
  • James
    James over 5 years
    I keep forgetting that sometimes the user is "centos" instead of "ec2-user". This jogged my memory though.
  • James
    James over 5 years
    It was "centos" in my case.