How to Setup Password Authentication For AWS ec2 Instances

Setup Password Authentication For AWS ec2 Instances

In this tutorial, I have added the configurations required for ec2 user password authentication for AWS ec2 Linux instances.

What is the default password for ec2?

By default, ec2 instances don’t have password authentication. You have to use the private key to connect to the instances.

However, you might have situations to use ec2 password-based authentication for your ec2 instances. So it is possible to set up an ec2 user password manually.

Setup Password Authentication For AWS ec2 User

I assume that you have an instance up and running. Follow the steps given below for the ec2 password authentication setup.

Note: I highly discourage using ec2 user password authentication on cloud instances unless required. It is always safe to use private key-based authentication.

Let’s get started with the setup.

Step 1: Log in to the server using the ssh client of your choice using the private key. For Windows machines, you can use putty for connecting to the instance. If you want the steps, you can follow this article. Connecting ec2 instance using putty.

If you are using Mac or Linux, you can use the following command to connect to the instance.

ssh -i your-key.pem username@(public-ip-address)

Step 2:  Open the sshd_config file.

sudo vi /etc/ssh/sshd_config

Step 3:  Find the line containing “PasswordAuthentication” parameter and change its value from “no” to “yes

PasswordAuthentication yes
ec2 user password setup

If you want to set up “root” ec2 user password, find  “PermitRootLogin” parameter and change its value from “prohibit-password” to “yes

After the changes, save the file and exit.

Note: If you are looking for a managed cloud hosting solution using AWS cloud, check out Cloudways Hosting. It makes your AWS cloud hosting easy with less administrative overhead.

Step 4: Setup ec2 user password using the “passwd” command along with the username.  

You need to enter the password twice. For example, if you want to set up a password for “ubuntu” user, use the following command.

sudo passwd ubuntu

In AWS, different ec2 instances have different user names. Following are the default usernames of common ec2 instances.

Instance Username
Ubuntuubuntu
Redhat Linuxec2-user
Amazon Linuxec2-user
CentOScentos
Debianadmin or root
Default ec2 usernames to set password

Step 5: Now, restart the “sshd” service using the following command.

sudo service sshd restart

Step 6: Now you can log out and log in using the password you set for the user. For example,

ssh [email protected]

I hope this ec2 user password setup article helps. Let me know in the comment section if you face any errors.

ec2 Instance Password FAQs

How do I find my EC2 instance password?

By default, the password authentication for ec2 Linux instances is disabled. Therefore, you need to allow PasswordAuthentication and manually create a password for the user. However, for Windows ec2 instances, you will get the option to create an admin password while creating the ec2 windows instance.

Conclusion

In this blog, you learned how to set up a password for ec2 Linux-based instances. Ensure that you safeguard your ec2 instances with security groups with SSH allow rule only to your IP. It ensures that no one else can access the SSH port.

0 Shares:
10 comments
  1. A big thank you, all sites including amazon telling using pem file only but not using password, you saved my time.

  2. I forgot my password and i tried to reset it in this way but it is asking for old password is there any other way to reset it

  3. Thank you for this! I’m not accustomed to not automatically having root access for the Deep Learning Linux AMI I used. This proved to be very helpful!

  4. Hello All, Please I need help removing or resetting the password for my ec2-user. (It’s Amazon redhat). Any tips on how to get this done? Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like