Security, Tech & Programming
How to login to aws ec2 instance using password

How to login to aws ec2 instance using password

Aws ec2 instance creates virtual server for us and provides us with a .pem file to login into the server. This is no doubt a very useful and secure process, however, it doesn’t allow logging in using the password by default.

To login to aws ec2 instance using password, we need to do following steps:

  1. Create a new user
  2. Make changes to the /etc/ssh/sshd_config file to allow password based login
  3. Reload ssh

Create a new user on ubuntu on aws ec2

To create a new user, simply run this command in the terminal:

sudo adduser newusernamehere

This will then prompt you to enter a password for this new user. Make sure that you create a strong password.

Now, we will edit the sshd_config file using:

sudo nano /etc/ssh/sshd_config

Look for this in the opened file (note, read the next block too before attempting this):

PasswordAuthentication no

We can now change no to yes and do ctrl + x to close the file, it will ask us to save it, press y and then press enter.

Note: you can also enable PasswordAuthentication from specific ip address only too. For that instead of changing no to yes in last step, add this block at the end of same sshd_config file:

Match address 192.168.2.0/24
    PasswordAuthentication yes

This will match ip addresses from 192.168.2.0 to 192.168.2.24. Change it to your own ip or ip range and save this file.

Now reload ssh service using command:

sudo service ssh reload

This will now implement new ssh configs that you made.

Leave a Reply

Your email address will not be published. Required fields are marked *

Hire Me!