Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.

Rasul Allah (sal Allahu alaihi wa sallam) said: "Restore the trusts of those who trust you, and deal not falsely with him who deals falsely with you." [Abu Dawud, Tirmidhi]

Search This Blog

Wednesday, October 11, 2017

How to connect to an AWS EC2 Instance.

Make sure you are able to ping the Public-DNS of the EC2 Instance.  By default you will not be able to ping the instance unless you modify the security group to allow the ICMP traffic.

shaiks@shaikslinux>ping ec2-instace-ip.us-east-2.compute.amazonaws.com
PING ec2-instace-ip.us-east-2.compute.amazonaws.com (instace-ip):
64 bytes from instace-ip: icmp_seq=0 ttl=232 time=22 ms
64 bytes from instace-ip: icmp_seq=1 ttl=232 time=20 ms
64 bytes from instace-ip: icmp_seq=2 ttl=232 time=20 ms

----ec2-instace-ip.us-east-2.compute.amazonaws.com PING Statistics----
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max/med = 20/21/22/20

Now try to connect to the Instance using the private key.

shaiks@shaikslinux>ssh -i "aws_key1.pem" ec2-user@ec2-instace-ip.us-east-2.com                          pute.amazonaws.com
Last login: Wed Oct 11 14:29:40 2017 from

       __|  __|_  )
       _|  (     /   Amazon Linux AMI

No packages needed for security; 1 packages available
Run "sudo yum update" to apply all updates.

[ec2-user@ip-172-31-46-150 ~]$ id
uid=500(ec2-user) gid=500(ec2-user) groups=500(ec2-user),10(wheel)

update the packages:

[ec2-user@ip-172-31-46-150 ~]$ sudo yum update
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                | 2.1 kB     00:00
amzn-updates                                             | 2.5 kB     00:00
Resolving Dependencies
--> Running transaction check
---> Package amazon-ssm-agent.x86_64 0: will be updated
---> Package amazon-ssm-agent.x86_64 0: will be an update
--> Finished Dependency Resolution

Dependencies Resolved

 Package              Arch       Version                 Repository        Size
 amazon-ssm-agent     x86_64        amzn-updates     9.1 M

Transaction Summary
Upgrade  1 Package

Total download size: 9.1 M
Is this ok [y/d/N]: y
Downloading packages:
amazon-ssm-agent-         | 9.1 MB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : amazon-ssm-agent-      1/2
  Cleanup    : amazon-ssm-agent-       2/2
  Verifying  : amazon-ssm-agent-      1/2
  Verifying  : amazon-ssm-agent-       2/2

  amazon-ssm-agent.x86_64 0:


Change to root user and modify the password for ec2-user.

[ec2-user@ip-172-31-46-150 ~]$ sudo su -
[root@ip-172-31-46-150 ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@ip-172-31-46-150 ~]# passwd ec2-user
Changing password for user ec2-user.
New password:
BAD PASSWORD: The password is shorter than 8 characters

[root@ip-172-31-46-150 ~]# passwd ec2-user
Changing password for user ec2-user.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

[root@ip-172-31-46-150 ~]#

No comments: