“whoami”

John Tyree
5 min readSep 26, 2023

--

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.

  1. First, lets open up the AWS console and login using IAM user.
Select IAM user and not Root 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.

Select EC2

3. After navigating to the EC2 dashboard, lets Launch an instance.

Launch Instance

4. After launching your instance, name the instance something unique. I will use “secondluitprojectjlt” for mine.

Enter an unique name for the instance.

5. First, we will setup the instance for a Linux SSH connection. Select “Amazon Linux” for the AMI.

Amazon Linux should be the default selection, if not, go ahead and select it!

6. For Instance type, leave it as default “t2.micro”

Select t2.micro for instance type.

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.

The connect button will be greyed out until you select which instance you want to connect to.

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.

I am using a MAC, so I will be using Terminal for my command line and change the directory to downloads using “CD” command.

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:

It connected successfully!

19. Next, we will run the command “whoami” for verification.

The “whoami” command returned our username, it was successful!

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!

--

--