To launch an EC2 instance on AWS, open the EC2 console, choose Launch instance, name it, pick an Amazon Machine Image (AMI) such as Ubuntu or Amazon Linux, choose an instance type, select or create a key pair, configure a security group that allows SSH, and press Launch. A few minutes later the instance has a public IP address you can connect to.
EC2 (Elastic Compute Cloud) is Amazon's virtual server service. This guide follows the console wizard step by step, explains the settings that matter for security and cost, and shows how to connect, stop and terminate the instance so you do not pay for something you forgot.
You need an AWS account with a payment method, and you should sign in as an IAM user or through IAM Identity Center rather than as the root user for daily work. Protect the root user with multi-factor authentication and do not create access keys for it.
Also decide:
Name tag.An AMI is the template for the root disk and operating system. For a first server pick Ubuntu Server LTS or Amazon Linux. Both are maintained and work with the standard login users (ubuntu and ec2-user). Use the architecture that matches the instance type: x86_64 for Intel and AMD, or arm64 for Graviton.
An instance type sets vCPU, memory and network capacity. The names follow a pattern: family, generation and size, for example t3.micro. The t family is burstable, which suits light workloads that are idle most of the time. Graviton types such as t4g are often cheaper for the same capacity, but your software must support arm64. Check the pricing page and the Free Tier list for the types available to you.
The key pair lets you log in without a password. Create a new key pair, choose ED25519 (or RSA if you must support old tools) and the .pem format for OpenSSH. The console downloads the private key once. Store it safely; AWS cannot show it again.
A security group is a stateful firewall attached to the instance. For SSH, add an inbound rule for type SSH on port 22 and set the source to My IP rather than 0.0.0.0/0. If you will host a website, add HTTP on port 80 and HTTPS on port 443 from anywhere. Everything not allowed inbound is blocked, and all outbound traffic is allowed by default.
The default root volume is an EBS disk, often 8 GiB. Increase it only if you need the space; you pay per GiB per month. Keep Delete on termination enabled for throwaway servers so the disk disappears with the instance.
Open the instance in the console, copy the Public IPv4 address and connect. First restrict the key file permissions, or SSH refuses it:
Use ec2-user as the username for Amazon Linux, and replace the IP with yours. You can also use the Connect button, which opens a browser-based terminal (EC2 Instance Connect or Session Manager).
If the connection times out, the usual causes are a security group without port 22, a source address that no longer matches your IP, or a subnet without a route to an internet gateway.
The public IPv4 address assigned at launch changes when you stop and start the instance. If a domain name points at the server, allocate an Elastic IP and associate it with the instance so the address stays fixed. AWS charges for public IPv4 addresses, and an Elastic IP that is not attached to a running instance also costs money, so release it when you no longer need it.
| Action | Compute billing | Disk (EBS) billing | Data kept |
|---|---|---|---|
| Stop | Stops | Continues | Yes |
| Terminate | Stops | Stops if delete on termination is on | No |
Stopping is like shutting down a computer; terminating deletes the instance. When you finish, terminate the instance, release any Elastic IP, and delete snapshots and unused volumes. Create a budget with an alert in AWS Billing so you are told if spending passes a limit.
Ubuntu Server LTS or Amazon Linux. Both have good documentation and regular security updates.
OpenSSH rejects private keys readable by other users. Run chmod 400 my-key.pem and try again.
It works, but automated scanners will hit it constantly. Limit the source to your own IP address, or use Session Manager so no inbound SSH port is needed.
A stopped instance keeps its disk and can start again. A terminated instance is deleted for good.
Launching an EC2 instance means choosing an AMI, an instance type, a key pair, a locked-down security group and storage, then pressing Launch. Connect with ssh -i key.pem user@public-ip, use an Elastic IP when the address must stay fixed, and terminate everything when you are done to avoid charges.