How to configure password in Amazon ec2 instance

ansxuman

Anshuman

Posted on June 27, 2022

How to configure password in Amazon ec2 instance
  • In this tutorial, I have added the configurations required for ec2 user password authentication for AWS ec2 Linux instances.
  • As by default ec2 instance don't have any password .Follow these simple steps to configure password in your linux instance .

Note:- It is not recommended to configure password in cloud instances unless required .Private key-based authentication is always the safest way to access cloud instances.

Step 1: Log in to the linux machine using ssh client of your choice using the private key.

  • For Windows machines, you can use putty for connecting to the instance. Click here to know how to use putty on Windows .

  • 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)
Enter fullscreen mode Exit fullscreen mode

Step 2: Enter the following command to open sshd_config file

sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

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

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

Step 4: Now press ctrl + x button and then click on Y button to save the changes

Now press ctrl + x button and then click on Y button to save the changes

Step 5: 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 “centos” user, use the following command.

sudo passwd centos
Enter fullscreen mode Exit fullscreen mode

In AWS, different ec2 instances have different usernames. Following are the default usernames of some popular ec2 instances.

Instance Username
Ubuntu ubuntu
Redhat Linux ec2-user
Amazon Linux ec2-user
CentOS centos
Debian admin or root

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

sudo service sshd restart
Enter fullscreen mode Exit fullscreen mode

Step 7: Once the "sshd" service is restarted successfully , you can log out and log in using the password you set for the user.
For example,

ssh ubuntu@34.10.100.1
Enter fullscreen mode Exit fullscreen mode

I hope this "How to configure password in Amazon ec2 instance" article helps. Let me know in the comment section if you face any errors.

💖 💪 🙅 🚩
ansxuman
Anshuman

Posted on June 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related