This is a common issue for the developers to access ec2 instances by username and password authentication. It requires a few steps to do that.
First, login as root using the key pairs.
Second, create a user
sudo adduser username
Third, you need to grant root level permission to the new user
visudo
Add following line
username ALL=(ALL) ALL
Forth, edit /etc/ssh/sshd_config
setting and then set PasswordAuthentication
to yes. Open the vim or nano
sudo vim /etc/ssh/sshd_config
Find and set PasswordAuthentication to yes
PasswordAuthentication yes
Finally, restart the ssh
daemon
For Ubuntu
sudo service ssh restart
For CentOS
sudo service sshd restart
Done, now you are able to login into your ec2 instance without the key pairs. Happy Hacking 🙂