Five Minute Guide to EC2
Published: 2021-08-18 04:37:24

I've made this as literal and direct as I can. Want to spin up an EC2 instance? Follow these steps to the letter, and unless AWS has changed their settings, you'll be in business. Any corrections or comments are welcome.

###Sign In
Navigate to `https://aws.amazon.com/` and click Sign In to the Console.

You're now in your AWS Management Console.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zxn7r77hv242jfdjfzj.png)

###Navigate to EC2
EC2 is a service that Amazon provides. From your AWS Management console, use either of these two options to open up the EC2 Dashboard:

1) Select from Recently Visited Services:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh8mhk41zr3z1x9j1bp6.png)

**or**

2) Select from the *Services* dropdown menu located next to the AWS logo (top-left of the page).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un6wmku0oe2skqa1bvi9.png)

###Navigate to Instances
Click either of these buttons to reach the Instances page.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmpjmu3785xavz96rugm.png)

###Launch an Instance
Click the bright orange button:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fewhu75rawqqdwtmeken.png)

###Choose an Image
I chose `Amazon Linux 2 AMI (HVM), SSD Volume Type`
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rinwx781945wlttdpz6.png)

If you're using Ubuntu (recommended) you only have to adjust one step, which I'll point out below.

###Select the Free Tier:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86fcwjzop851r5eajd0k.png)

Click that blue button (`Review and Launch`)!

###Launch!
If you'd like to improve the security of your site, go ahead and configure security groups. If you're interested in launching a low-stakes instance for learning purposes (like I am), hit the blue button!

###Create a key
In order to be able to access your instance from the terminal on your computer via SSH, you'll need a private/public key pair. That last button click should've activated this modal:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86fcwjzop851r5eajd0k.png)

###Move the key to your Working Directory
Once you've chosen a project-specific name and downloaded it, for convenience, you may want to move the key into your project folder.

I avoided the command line for this and literally dragged and dropped it from my 'downloads' folder into my project folder.

### .gitignore the Key file
Make sure you add the .pem key file to your .gitignore file. That way it won't be exposed publicly when on your next commit/push.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcr8om8adybbxuzytv0w.png)

###Rename your Instance
Go back to the Instances page. The same page you see at step 4. Rename your instance (I recommend naming it identically to your project).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3f2swklp931ekf6a05j.png)

###Find your IP Address
Enter into your instance by clicking the blue `Instance ID` link at the above page.

Copy your ip address:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0ylxzeg7eqqz2mmvzqu.png)

###Connect to your Instance
Alright, we're right at the doorstep.

Let's enter into your instance console via SSH. Here's how.

Run this command from your project directory in your terminal:

`ssh -i KEYNAME.pem ec2-user@IPADDRESS`

*(if you're using an ubuntu server, replace `ec2-user` with `ubuntu`)*

replacing KEYNAME with the name of your key and IPADDRESS with the info copied a few steps earlier. (`ec2-user` should be the default user name if you've followed the exact steps I've provided).

hit `enter`.

If you get this message:

>Are you sure you want to continue connecting (yes/no)? y
>Please type 'yes' or 'no': yes

Type `yes`

###Change Key Permissions

If you see the following message:

>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>Permissions 0644 for 'SDC.pem' are too open.
>It is required that your private key files are NOT accessible by others.
>This private key will be ignored.
>Load key "SDC.pem": bad permissions
ec2-user@18.118.34.126: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

enter this command:

`chmod 400 KEYNAME.pem'.

Again, replace `KEYNAME` with the name of your key.

###SSH again

Run this command a second time:

`ssh -i KEYNAME.pem ec2-user@IPADDRESS`

(don't forget to replace with the correct name/address).

###et Voila!
If you see a command prompt like this:

`[ec2-user@ip-172-31-29-141 ~]$`

you've made it!