karishma seetharaman
karishma seetharaman

Reputation: 53

How do I connect to EC2 instance in AWS?

I am trying to connect to an EC2 instance with the key. But I get an error saying

No supported authentication methods available (the server sent: public key")

In the command window I get:

Using username "ec2-user"

Server refused our key

. Please help me

Upvotes: 2

Views: 2290

Answers (2)

IV.
IV.

Reputation: 9511

I will try to help! Suppose you are trying to connect using the PuTTY SSH client on your local machine. (Connecting with an FTP client like WinSCP is very similar).

Short answer: You need to let PuTTY know your ec2user IP address and associate the private key of the EC2 instance with the PuTTY session. On the AWS side you need to create a security group that allows inbound access from your IP address to your EC2 instance for SSH on port 22.

__

Long answer 😊:

  1. Go to your EC2 page and click [CONNECT] [enter image description here]1

  1. Copy the ec2User IP address to PuTTY. enter image description here

  1. When you created the EC2 instance, you were prompted to download the public/private key pair. You need that private key. If you don’t have that file, things are more complicated. (See Change key pair for ec2 instance). But hopefully, you can find the private PuTTY Private Key file downloaded on your local machine: enter image description here

  1. Save the session. PuTTY should be all set up now.

  2. Now on the AWS side, you need to make a new security Group: enter image description here


  1. Create the group and ADD an Inbound Rule: enter image description here

  1. Go back to EC2 and add security group to EC2. enter image description here

  1. In the dialog that pops up, check the security group that you just created for PuTTY remote access and click [Assign Security Groups]

Now give it a try!

I hope this works for you like it does for me.

ONE FINAL TIP: Make sure that you associate an Elastic IP address to the instance. Otherwise, this connection might stop working when someday you reboot your EC2. The elastic IP pins it down.

Upvotes: 4

Ali
Ali

Reputation: 1631

Verify that you are connecting with the appropriate user name for your AMI. Type the user name in User name in the PuTTY Configuration window.

The appropriate user names are as follows:

For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.

For a CentOS AMI, the user name is centos.

For a Debian AMI, the user name is admin or root.

For a Fedora AMI, the user name is ec2-user or fedora.

For a RHEL AMI, the user name is ec2-user or root.

For a SUSE AMI, the user name is ec2-user or root.

For an Ubuntu AMI, the user name is ubuntu.

Otherwise, if ec2-user and root don't work, check with the AMI provider.

You should also verify that your private key (.pem) file has been correctly converted to the format recognized by PuTTY (.ppk).

Upvotes: 1

Related Questions