instanceofGod
Posted on May 16, 2022
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
- Setup a password for the user using the passwd command
sudo passwd username
- Open and modify the
sshd_config
file.
sudo vim /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config
If you prefer to use nano as editor
Changes the PasswordAuthentication line from ‘no’ to ‘yes’
PasswordAuthentication yes
- Enable root login, Change value from “prohibit-password” to “yes” (Optional)
PermitRootLogin yes
- Restart the “sshd” service using the following command.
sudo service sshd restart
or
sudo systemctl restart ssh
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!
Posted on May 16, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.