I want to set up password based authentication (non key) on AWS EC2 ubuntu instance. But at the same time I want to keep the key based authentication also on the same instance. Will it be possible and how we can do that?
Yes, it is possible.
To set up password based authentication (non key), you can achieve this by following the below setup,
Step 1: Create password for the root user
sudo passwd root
Step 2: To allow root password, edit sshd_config file and set the "PasswordAuthentication" value as "yes"
vi /etc/ssh/sshd_config PasswordAuthentication yes RSAAuthentication yes PermitRootLogin yes
Step 3: For key based authentication,
sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/
Step 5: After that make sure the "/root/.ssh/authorized_keys" file should start with ssh-rsa content
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10"
Step 6: Finally, to reflect your configuration changes, you need to restart ssh services, so use the below command.
sudo service ssh restart