DEV Community

Cover image for Enable Password Authentication in AWS EC2 Instance
instanceofGod
instanceofGod

Posted on • Edited on

Enable Password Authentication in AWS EC2 Instance

Password authentication is disabled by default in aws ec2 instance. The only way to access your server is by using ssh with -i flag and followed by private key attached to the server.

However, there are scenarios when you may need to access the server with just username and password. Take note that this method of accessing your server is not encouraged, as it could open your server to attacks.

How to Enable Password Authentication in EC2

First, you have to ssh into your server with your private key to set password for the user and also make some changes to the sshd_config file.

The steps to enable password authentication are highlighted below:

  • Login to server
ssh -i privatekey username@host_ip
Enter fullscreen mode Exit fullscreen mode
  • Setup a password for the user using the passwd command
sudo passwd username
Enter fullscreen mode Exit fullscreen mode
  • Open and modify the sshd_config file.
sudo vim /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode
sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

If you prefer to use nano as editor

Changes the PasswordAuthentication line from ‘no’ to ‘yes’

PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode
  • Enable root login, Change value from “prohibit-password” to “yes” (Optional)
PermitRootLogin yes
Enter fullscreen mode Exit fullscreen mode
  • Restart the “sshd” service using the following command.
sudo service sshd restart

or 
sudo systemctl restart ssh
Enter fullscreen mode Exit fullscreen mode

That’s all you have to do. Now you can login to the ec2 server using the password you set for the user, without the private key.

When you type the command below, you will be prompted to enter your password!

Top comments (0)