If you lose your Amazon EC2 SSH key and can’t log in to your instance, this isn’t a big problem as long as your instance is EBS-based and uses an Elastic IP.
1. Upload your new SSH key, or use one generated by AWS.
2. Create an AMI of your instance.
3. Launch a new instance from your AMI and select the new SSH key.
4. Log in to your instance with the default user (ubuntu or ec2-user, depending on your original AMI).
5. Reassign the Elastic IP to the new instance.
6. Turn off the old instance and terminate it.
Modern Alternatives (No Instance Replacement Required): Today you can usually regain access without cloning an AMI by connecting via AWS Systems Manager Session Manager, pushing a temporary key through EC2 Instance Connect, or stopping the instance to attach its root EBS volume to a temporary rescue VM and updating ~/.ssh/authorized_keys directly.
Alongside swap, keeping a tiny VM responsive came down to caching and restraint: placing Varnish in front of Apache absorbed static/anonymous reads before spawning memory-heavy worker processes, while PHP bytecode caching (APC back then, replaced natively by PHP OPcache today) avoided recompiling scripts on every request.
Cloud & Modern Linux Caveats: Heavy swapping on network-attached EBS volumes adds latency and burns through storage IOPS burst credits, so keep vm.swappiness=10 and treat swap strictly as an OOM safety net. On modern Linux kernels, compressed in-memory swap with zram is much faster and avoids unnecessary disk writes, while older tools like prelink are deprecated because of ASLR.
How do you get started with AWS for free?
Just go to https://aws.amazon.com/free/ and create your account.
A credit card is required, even for a free account.
Historical Context (2013): When this article was written, AWS Free Tier offered t1.micro instances with 613 MB of RAM. Modern AWS Free Tier accounts provide t2.micro / t3.micro instances (1 GB RAM) for 12 months plus selected Always Free allowances (such as DynamoDB and AWS Lambda).
What can you do with the free account?
It’s up to you! If you are building a light-traffic website, the Free Tier can handle it. 🙂
You can have up to two EC2 instances (1 Linux, 1 Windows) with 613 MB of RAM and up to 30 GB of EBS storage. You can use all 30 GB on a Linux instance, which is the best way to spend your “free” resources (Windows is memory-hungry).
You can have up to one RDS instance (PostgreSQL, MySQL, …) with 20 GB of database storage and 20 GB for backups.
You can use Amazon S3 with up to 5 GB of storage and up to 20k PUT and 20k GET requests.
You can have up to one Memcached node with 213 MB of RAM.
And a few other services (ELB, DynamoDB, SNS, CloudWatch, …).