How to Setup Password Authentication For AWS EC2 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. So it is possible to set up an ec2 user password manually.
Step 1:
Log in to the server using the ssh client of your choice using the private key or SSM (Session Manager). For Windows machines, you can use putty for connecting to the instance. If you are using Mac or Linux, you can use the following command to connect to the instance.
1
ssh -i your-key.pem username@(public-ip-address/private-ip-address)
Step 2:
Open the sshd_config file
1
sudo vi /etc/ssh/sshd_config
Step 3:
Find the line containing “PasswordAuthentication parameter and change its value from “no” to “yes“
1
PasswordAuthentication yes
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.
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.
1
sudo passwd ubuntu
In AWS, different ec2 instances have different user names. Following are the default usernames of common ec2 instances. For details, you can visit this reference.
Step 5:
Now, restart the “sshd” service using the following command.
1
sudo service sshd restart
Step 6:
Now you can log out and log in using the password you set for the user. For example,
1
ssh ubuntu@xxxx.yyyy.zzzz.aaa