How to find the username of the instance launched in amazon-ec2?

Viewed 32503

I m having trouble connecting to amazon ec2 instance using ssh. The key pair matches. On google-ing a bit i find that username is not the same for all instances. I assumed its always ec2-user. How can I find the username of the instance that I have launched?

I am getting this error:

Permission denied (publickey).

on trying this:

ssh -i test-instance.pem  ec2-user@23.22.214.148

Any help will be appreciated.

6 Answers

Description-

Each Linux instance launches with a default Linux system user account. The default user name is determined by the AMI that was specified when you launched the instance. For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user. For CentOS, the user name is centos. For Debian, the user name is admin or root. For Fedora, the user name is ec2-user or fedora. For RHEL, the user name is ec2-user or root. For SUSE, the user name is ec2-user or root. For Ubuntu, the user name is ubuntu. Otherwise, if ec2-user and root don't work, check with your AMI provider.

Amazon AWS has listed default usernames here:

Default usernames for AWS AMIs

Get the default user name for the AMI that you used to launch your instance:

  • For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.
  • For a CentOS AMI, the user name is centos or ec2-user.
  • For a Debian AMI, the user name is admin.
  • For a Fedora AMI, the user name is fedora or ec2-user.
  • 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.
  • For an Oracle AMI, the user name is ec2-user.
  • For a Bitnami AMI, the user name is bitnami.
  • Otherwise, check with the AMI provider.

You can reference : click here for more details

I think the name is fine. The error is that you may have to change the permissions of the key with chmod 400. Then it should let you connect. If the username is wrong you'll get another error, but at least you'll have moved past this one

Here simple and sweet answer

Change pem file mode

chmod 400 my.pem

Access ec2 instance in terminal

ssh -i my.pem ubuntu@ec2-xx-xxx-xx-xx.us-east-1.compute.amazonaws.com
Related