---
tags: notes, aws, ec2
---
# AWS: How to start an EC2 and `ssh` it
This note goes through the simplest way to start an EC2 and connect it with ssh pem key. The following steps are performed with AWS Educate account. For personal or enterprise usage, the steps are different when logging in.
## Access to AWS web console
1. Go to AWS login page. For example [AWS Educate login page](https://www.awseducate.com/signin/SiteLogin).
*note that AWS Educate account can't be logined to the AWS web console directly. You have to login on AWS Educate login page mentioned in this step.
3. Select **AWS Educate Starter Account** on [AWS account page](https://www.awseducate.com/student/s/awssite). You should see your account status and remaining credits.
4. Click **AWS Console** on the account status page you just entered on the above step. This should lead you to the **AWS web console**.

4. You can select region of a datacenter where your service is applied at the upper right coner for minimizing latencies. However, the price of a service varies depending on different regions.
> [Chart source](https://www.concurrencylabs.com/blog/choose-your-aws-region-wisely/). For more information, check [Official Billing Guide](https://docs.aws.amazon.com/account-billing/index.html).
> 
## Create Network enviroment for EC2
This step create rules assigning private/public IP for instances.
1. Create VPC with VPC wizard
> AWS Service=> VPC=> Launch VPC Wizard(Orange button)=> Select VPC with a Single Public Subnet
> or click [here](https://console.aws.amazon.com/vpc/home?region=us-east-1#wizardFullpagePublicOnly:)
2. Leave everything default and click Create VPC
> 
3. You should see an available vpc in [vpc status page](https://console.aws.amazon.com/vpc/home?#vpcs:) and an available subnet in [subnet status page](https://console.aws.amazon.com/vpc/home?region=us-east-1#subnets:sort=SubnetId).
## Launch an EC2 instance
1. After you have login and now on the [AWS Console webpage](https://console.aws.amazon.com/console/home), do the following:
> AWS Service=> EC2=> Launch instance(orange button)
2. Select an AMI(Amazon Machine Image) that fits your need. I choose `Ubuntu Server 18.04 LTS (HVM)` since I'm familiar with ubuntu 18.04 and it's **Free tier eligible**.
> Click Select.
>
3. Configure hardware resources(vCPUs, memory, Network performance and so on):
> Click Next
> 
4. Create network
> Networkd and Subnet should be automatically selected as the ones you just create.
> Make sure you have **Auto-assign Public IP** Enabled.
>
5. Configure size of storage
> 
6. It's suggested that you add tag for this instance. It's like naming a varible when coding. It helps alot for maintance.
> 
7. Configure Security Group
> Add a rule for ssh. If you are developing an static web page, you can add Type: HTTPS, Port Range: 443, Source: Anywhere. And then click Review and Launch.
> 
8. Review and Launch
> Review your instance and click Launch
> Create a new key pair and download the key pair. This key can only be downloaded once, so preserve it carefully.
> Click Launch Instances
> 
## `ssh` into the instance
I use [mobaxterm](https://mobaxterm.mobatek.net/) as a `ssh` console. You can use any other one, such as PuTTY or cmd of windows.
*Note that the user name is ubuntu, however default user name varies depending on diferent images selected. You can check the username by: right click the instance=> Connect.
1. Check for instance's public IPv4
> Go to the [instance page](https://console.aws.amazon.com/ec2/v2/home?#Instances:)=> Click the instance you just created.
> You should see public IPv4 of the instance.
> 
2. Connect it with pem(key pair you just downloaded)
> MobaXterm=> Sessions=> SSH
> Remote host: IP of the instance
> Check Specify username: ubuntu
> Uncheck X11-Forwarding
> Check Use private key: Select the key pair just downloaded.
> Click OK
> 
## Trouble shooting
- Kicked out: Session expired:
> 
Repeat `Access to AWS web console` of this note should solve the problem.