How to access EC2 instance without .pem file.

Here are the steps to login into Ec2 instance without .pem file.

Login into Ec2 instance with .pem file.

$ ssh -i "aws-key.pem" ec2-user@ec2-35-154-198-16.ap-south-1.compute.amazonaws.com

Create a new user to access the Ec2 instance with strong password

$ sudo useradd USER_NAME
$ passwd USER_NAME
Changing password for user root.
New password: 
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
Retype new password: 
passwd: all authentication tokens updated successfully.
$

Add the user to sudoers file visudo command and add the below line

USER_NAME ALL=(ALL) ALL

$ sudo visudo

Enable password authentication by editing /etc/ssh/sshd_config file.

Initial Configuration:

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication no

Change to below configuration:

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no

Comment for no and uncomment for yes

Restart sshd service.

# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
#

Now, logout from the instance and login with your password.

$ ssh USER_NAME@ec2-35-154-198-16.ap-south-1.compute.amazonaws.com

It will ask for your password. Enter the password and hit Enter key.

Advertisements

Post your Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s