Why am I receiving "imported-openssh-key" or "Putty Fatal Error" errors when connecting to my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance?

Last updated: 2020-10-06

I'm receiving "imported-openssh-key" or "Putty Fatal Error" errors when connecting to my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. How can I fix these errors?

Short description

When connecting to my Linux instance using SSH, I receive an error similar to the following:

"Using username "root". Authentication with public key "imported-openssh-key" Please login as the user "ec2-user" rather than the user "root"."

-or-

When using the PuTTY client, I receive an error similar to the following:

"PuTTY Fatal Error: Disconnected: No supported authentication methods available (server sent: publickey) OK

These errors might occur under the following circumstances:

  • You're not connecting with the appropriate user name for your AMI when you negotiate an SSH session with an EC2 instance.
  • You're using the wrong private key when you negotiate an SSH session with an EC2 instance.

Resolution

Verify that you're connecting with the correct user name

On your local machine, verify that you're connecting with an appropriate user name. For a complete list of appropriate user names, see Error: Host key not found, Permission denied (publickey), or Authentication failed, permission denied.

Verify that the private key is correct

1.    Open the Amazon EC2 console, and then choose Instances.

2.    Find the EC2 instance you want to connect to using SSH.

3.    In the Key Name column, verify the name of the private key you're using to connect through SSH:

PuTTY

Verify that the SSH private key matches the private key you see in the Key Name column for your EC2 instance in the console.

Verify that you've converted your private key (.pem) file to the format recognized by PuTTY (.ppk). For more information, see Converting your private key using PuTTYgen.

macOS or Linux

Make sure that you've changed the permissions on your key pair file so that only you can view it by running the following command:

$ chmod 400 my-key-pair.pem

Check the directory and file name that you specify after the -i flag to make sure it’s the correct path to your private key, as shown in the following example command:

$ ssh -i my-key-pair.pem ec2-user@52.4.XX.XX