Sunday, May 29, 2016

Access AWS Linux instance over SSH


How to access your AWS Linux instance over SSH?

There are two options:

1. Access with your .pem key file, which you obtained from AWS when creating an instance

2. Access with password



Before you will be able to ssh into your instance via option 2., you will have to set up the account and password via option 1.


Option 1. steps:

1. Log into your AWS web portal and find your Linux instance in the instances list

2. Right click on the instance, and click on the 'connect' option

3. You will find your Public DNS address (e.g. ec2-your-instance.us-your-region.compute.amazonaws.com)

4. Find your .pem key file path (e.g. /user/doc/my-key-file.pem), and do ssh in your client by

ssh -i /user/doc/my-key-file.pem ec2-user@ec2-your-instance.us-your-region.compute.amazonaws.com

Note: ec2-user is the default user name for your Linux instance. If it happens to be different, refer to this for details of how to obtain it. If it asks you about RSA key fingerprint, just type yes.

5. If You have successfully logged into the instance over SSH after previous 4 steps, you will now be able to set up password access over ssh to your instance, so that you don't always need your .pem key file.


Option 2. set up password access:

1. ssh -i /user/doc/my-key-file.pem ec2-user@ec2-your-instance.us-your-region.compute.amazonaws.com

2. $ cd /

3. $ sudo useradd -s /bin/bash -m -d /home/USERNAME -g root USERNAME

4. $ sudo passwd USERNAME
Enter new pwd:
Retype new pwd:

5. add the user as a sudoer (optional):

$ sudo visudo
and add the following line to the file:
USERNAME  ALL=(ALL:ALL) ALL

6. enable password access

$ sudo vi /etc/ssh/sshd_config
and change PasswordAuthentication from 'no' to 'yes'

7. restart ssh service by

$ sudo /etc/init.d/ssh restart

or

$ sudo /etc/init.d/sshd restart

9. log out and log in using

$ ssh USERNAME@ec2-your-instance.us-your-region.compute.amazonaws.com
Enter pwd:









No comments:

Post a Comment