Recommended Settings for Creating an EC2 Instance
| Item | Recommended value |
|---|---|
| AMI | Ubuntu 22.04 LTS |
| Instance type | t3.micro (testing) / t3.small (small-scale) |
| Storage | gp3 20GB+ |
| Key pair | Create a new one and store the .pem file securely |
Security Group Inbound Rules
| Port | Source | Purpose |
|---|---|---|
| 22 | My IP | SSH |
| 80 | 0.0.0.0/0 | HTTP |
| 443 | 0.0.0.0/0 | HTTPS |
Allow SSH only from your IP — opening it to 0.0.0.0/0 is a security risk.
SSH Access
Bash
chmod 400 my-key.pem
ssh -i my-key.pem ubuntu@<EC2-PUBLIC-IP>
# ~/.ssh/config
Host myserver
HostName 123.45.67.89
User ubuntu
IdentityFile ~/.ssh/my-key.pem
ServerAliveInterval 60
ssh myserverInitial Setup After Connecting
Bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget git vim htop build-essential ufw fail2ban
sudo timedatectl set-timezone Asia/Seoul
# file (t3.micro )
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo ufw allow 22/tcp && sudo ufw allow 80/tcp && sudo ufw allow 443/tcp
sudo ufw enableAWS CLI Setup
Bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip && sudo ./aws/install
aws configure
# Region: ap-northeast-2
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[InstanceId,State.Name,PublicIpAddress]' \
--output tableInstance Type Selection Criteria
| Family | Use case | Example |
|---|---|---|
| t3/t4g | General purpose, burstable | Small web servers |
| m6i/m7i | General purpose, consistent performance | API servers |
| c6i/c7i | Compute-intensive | Rendering, batch jobs |
| r6i/r7i | Memory-intensive | Databases, caches |
Editorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)AWS documentation ↗Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.