Login to Ec2-Instance without .pem file for Unix OS.
Hey Guys!! Hope you are all having a good day.
So here, I am having a new post for all of you. As we generally create an ec2-instance in AWS for our daily use or for learning purposes. But somehow we are using either using .pem file or a PPK file to connect with ec2-instance. As for the first time, it is necessary to use it but not oftenly
So, if in case if you don't need to connect with pem or a PPK file and directly login to your ec2-instance via your username then you have to follow these suggested steps.
1. While log in the first time to your EC2 instance use your .pem
file
ssh -i your_pem_file.pem ec2-user@ec2-________.compute-1.amazonaws.com
2. Create a new user that will access the instance using a password:
$ sudo useradd -s /bin/bash -m -d /home/USERNAME -g root USERNAME
where:
-s /bin/bash
: use/bin/bash
as the standard shell-m -d /home/USERNAME
: create a home directory at/home/USERNAME
-g root
: add to the grouproot
USERNAME
: the username of the new user
3. Create a strong password for the new user:
$ sudo passwd USERNAME
Enter new UNIX password:
Retype new UNIX password:
4. Add user to sudoers file by using sudo vi /etc/sudoers
and add the following line:
USERNAME ALL=(ALL:ALL) ALL
5. Enable password authentication policy by editing sudo vi /etc/ssh/sshd_config
: change PasswordAuthentication no
to PasswordAuthentication yes
6. Restart ssh:
systemctl restart sshd
Logout of your instance (exit
) and try your new login without the .pem
file:
$ ssh USERNAME@ec2-________.compute-1.amazonaws.com
USERNAME@ec2-________.compute-1.amazonaws.com's password: