DEV Community

Cover image for Accessing EC2 Linux instance without .pem file
HasOne
HasOne

Posted on • Updated on

Accessing EC2 Linux instance without .pem file

you may find a situation where you want to access your Linux instance from someone's else machine, but your Linux need the .pem key file and you don't want to carry your .pem file to other's machine. why not just create a password for ssh, so let's create it

1) first you have to log in to your Linux box using .pem

$ ssh -i your_pem_file.pem ubuntu@ec2-________.compute-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

2) create a user that will access the instance using a password

$ sudo useradd -s /bin/bash -m -d /home/USERNAME  -g root USERNAME
Enter fullscreen mode Exit fullscreen mode

3) create a strong password for the new created user

$ sudo passwd USERNAME
Enter new UNIX password:
Retype new UNIX password:
Enter fullscreen mode Exit fullscreen mode

4) Add user to the sudoers file by using sudo visudo command

USERNAME  ALL=(ALL:ALL) ALL
Enter fullscreen mode Exit fullscreen mode

5) Enable password authenticating by editing /etc/ssh/sshd_config file. and look for PasswordAuthentication

PasswordAuthentication no 
# change it to yes
PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode

6) restart ssh demaon

$ sudo systemctl restart ssh
Enter fullscreen mode Exit fullscreen mode

You're done, let's login by password

$ ssh USERNAME@hostname
Enter fullscreen mode Exit fullscreen mode

BOOM you dit it. Make sure to create a strong password as it's less secure using a password rather than .pem file.

Thank you so much for reading my article, I hope you got something to learn today. stay positive and happy coding.

anybody can succeed on the space, so don't listen to nay-sayer.

Top comments (0)