“whoami”
Objective:
For this article we are going to Launch an EC2 instance and allow SSH client connection. Stay tuned for a future article, we will launch another EC2 instance allowing RDP connection, and then we will swap SSH connection for SSM.
But wait, what is an EC2!?
An EC2 instance is a virtual server hosted in Amazon’s Elastic Compute Cloud. Instances are created from Amazon Machine Images (AMI) which are templates configured with an operating system.
- First, lets open up the AWS console and login using IAM user.
2. After getting logged into AWS, let's launch an EC2 instance. Type in the search bar for “EC2” and select the first option.
3. After navigating to the EC2 dashboard, lets Launch an instance.
4. After launching your instance, name the instance something unique. I will use “secondluitprojectjlt” for mine.
5. First, we will setup the instance for a Linux SSH connection. Select “Amazon Linux” for the AMI.
6. For Instance type, leave it as default “t2.micro”
7. Next, we will create a new key pair. Select the option to Create new key pair. Give the Key pair a name and leave the defaults and “create key pair” That keypair that you created will save to your downloads folder.
8. Under network settings, select “edit” in the right corner. The “VPC” can be default, but under “Firewall” we need to “Create Security group” go ahead and name your security group and description. For this article I will name the security group “secondluitprojectssh”.
9. Next, we will configure our inbound rules for our newly created security group to allow for ssh connection anywhere. After that is named select “add security group rule” and in the “type” field, select “ssh” from the drop down. Notice the port range will read 22. Under source type, select “anywhere” from the drop down.
10. All other settings we will leave as default and launch the instance.
11. Once, the instance has successfully launched, we are able to see it in the EC2 dashboard under “Instances” When ready the “Instance State” will read “Running”
12. Once our EC2 instance is running, we will select the checkbox to select our instance and press connect.
13. There will be a default username under the public IP address under the tab “username” make note of that username.
14. Let's locate the key file, we will need this information. For this instance, my keyfile is located in my downloads folder.
15. Open your terminal if using a MAC and Command Prompt if using Windows. Change your directory to where your key file is located. I will change my to downloads.
16. Since we know where our key file is located, lets navigate back to our browser in AWS and select “SSH” client. Run the command given in step 3 on your screen to ensure the key is not publicly viewable.
17. Next, we will copy the command line given to connect using ssh. Go to your Terminal or Command Prompt and past whats given.
18. After running the command, You should see the following:
19. Next, we will run the command “whoami” for verification.
20. Final step, we will stop/terminate our instance to be free of any charges. Select your instance and select the “Instance state” drop down and “stop” or “Terminate” your instance. Once your terminate the instance it cannot be started again, so make sure you are finished with that instance!