# 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](https://www.ssh.com/academy/ssh/putty/windows) 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.

```bash
ssh -i your-key.pem username@(public-ip-address)
```
**Step 2:**  Enter the following command to open sshd_config file

```bash
sudo nano /etc/ssh/sshd_config
```
**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“](https://cdn.hashnode.com/res/hashnode/image/upload/v1657055824874/Jj9go09wH.png)

**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](https://cdn.hashnode.com/res/hashnode/image/upload/v1657055826429/qtoGKhrNK.png)
 
**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.

```bash
sudo passwd centos
```

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.

```bash
sudo service sshd restart
```
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,

```bash
ssh ubuntu@34.10.100.1
```

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.
