ResilientX

EC2 Hardening: A Practical Security Checklist

Summary:

EC2 hardening step by step: IMDSv2, Session Manager instead of SSH, EBS encryption by default, least-privilege roles, patching and a checklist to audit against.

EC2 hardening means reducing what an attacker can do with an instance if they reach it, and making it harder to reach in the first place. In practice that comes down to seven areas: the instance metadata service, how people log in, network exposure, disk encryption, the instance's IAM role, patching, and logging. Get those right and most of the well-known EC2 attack paths close.

This guide walks through each area with the specific setting to change, why it matters, and how to check it, ending with a checklist you can audit against. It belongs to our series on AWS VPC security architecture, which covers the network around the instance.

What does an EC2 hardening checklist cover?

AreaSettingWhy it mattersHow to check
MetadataRequire IMDSv2Blocks token-less metadata requests, the classic credential theft pathInstance metadata options show token usage set to required
MetadataKeep the PUT hop limit at 1 unless containers need moreStops tokens leaving the instance through extra network hopsHop limit value in metadata options
AccessUse Session Manager instead of SSH or RDPNo inbound management ports, no SSH keys to loseNo security group allows 22 or 3389 from the internet
NetworkPrivate subnets and no public IP unless neededNothing to attack directly from the internetInstances with public IPs are listed and justified
NetworkLeast-privilege security groupsLimits lateral movementNo 0.0.0.0/0 except on intended public ports
DiskEBS encryption by default in every Region you useNew volumes and snapshot copies are always encryptedAccount setting enabled per Region; unencrypted volumes listed
IdentityLeast-privilege instance role, no stored access keysLimits what stolen credentials can doRole policies reviewed; no keys in files or user data
PatchingAutomated OS patching or regular image rebuildsCloses known vulnerabilitiesPatch compliance report or image age
LoggingSession, API and OS logs centralizedLets you reconstruct what happenedLogs arriving in the central account

The rest of this guide explains each line.

How do you lock down the instance metadata service?

Every EC2 instance can query a metadata service at a link-local address, and that service hands out, among other things, temporary credentials for the instance's IAM role. That makes it the first target when an application on the instance is vulnerable to server-side request forgery.

AWS offers two versions. According to the instance metadata documentation, IMDSv1 is a request and response method, while IMDSv2 is session-oriented: the caller first creates a session token with a PUT request, valid for between one second and six hours, and sends that token with every request.

You can configure an instance to accept only IMDSv2. Requests without a valid token then fail with a 401 error. IMDSv2 also rejects PUT requests that carry an X-Forwarded-For header, which defeats many proxy-based attacks.

The second setting is the hop limit. By default the response to the token PUT request has a hop limit of 1, so it cannot travel beyond the instance. AWS notes you may need a higher value for container services running on the instance. Raise it only where you actually run containers that need metadata.

One more reason this matters: network ACLs cannot block traffic to the metadata service, as our comparison of security groups vs NACLs explains. Protection has to live on the instance.

How should people log in to instances?

Not over SSH or RDP from the internet. AWS Systems Manager Session Manager gives shell access with no open inbound ports and no bastion hosts or SSH keys to manage. Access is controlled centrally with IAM policies, so you decide which users can open sessions on which instances.

Session activity is logged too: CloudTrail captures the Session Manager API calls, and session logs can go to an S3 bucket or a CloudWatch Logs log group. That gives you the audit trail an SSH key never did.

Once Session Manager works, remove inbound rules for ports 22 and 3389 from your security groups. If a team insists on SSH, restrict the source to a specific address range and rotate keys on a schedule.

How should you handle disks and snapshots?

Turn on EBS encryption by default. It makes the account enforce encryption of the new EBS volumes and snapshot copies you create.

Two details catch people out. First, the setting is Region-specific, so it must be enabled in every Region you use, including ones you use rarely. Second, it has no effect on existing volumes or snapshots. Existing unencrypted volumes need a migration, typically by copying a snapshot with encryption and restoring from it during a maintenance window.

Treat snapshots as data. A snapshot shared publicly or with the wrong account is a copy of your disk handed over in full.

What permissions should an instance role have?

As few as the workload needs. An instance role's temporary credentials are exactly what an attacker steals through the metadata service, so the role defines the blast radius.

  • Grant actions on named resources, not wildcards across services
  • Use separate roles for separate workloads instead of one shared role
  • Never store long-lived access keys on the instance, in user data or in images
  • Review role usage periodically and remove permissions nobody uses

These are standard identity and access management principles applied to machines.

How do you keep EC2 instances patched?

Pick one of two models and apply it consistently. Either patch running instances automatically on a schedule with a defined baseline and maintenance windows, or treat instances as disposable and rebuild them regularly from updated images.

The second model is easier to prove: the age of the image is the age of the patch level. The first suits long-lived servers that cannot be replaced easily. Either way, report patch compliance per instance so that a forgotten server shows up instead of hiding.

Which network settings belong to hardening?

Keep instances in private subnets unless they must accept traffic from the internet directly, and put a load balancer in front of those that must. Avoid public IP addresses on application and database servers.

Security groups should allow only the ports the workload uses, from the sources that need them, referencing other security groups instead of broad ranges. The full network design around the instance is covered in our AWS VPC security architecture guide.

What should you log on EC2?

Log three layers: API activity in your accounts, network flows at the subnet or interface level, and operating system and application logs from the instance itself. Session Manager adds session logs on top of those.

Send everything to a separate logging account that workload administrators cannot change, and alert on the events that matter most for hardening: changes to security groups, instance roles and metadata options, new public IP addresses, and logins that bypass Session Manager.

How do you check EC2 hardening at scale?

Manual checks do not survive the first busy quarter. Benchmark against the CIS AWS Foundations Benchmark for account-level settings and against a CIS operating system benchmark for the instance image, then monitor continuously for drift.

ResilientX cloud security posture monitoring connects to AWS, Azure and GCP through their APIs without agents, scans resources across all Regions, and flags open ports, misconfigured firewalls, risky IAM policies and public storage, with CIS AWS Foundations scoring. External attack surface management then confirms which instances are actually reachable from the internet. Assess your cloud security posture with ResilientX UEM to see where your instances stand today.

Frequently asked questions

Is requiring IMDSv2 enough to stop credential theft?

It closes the most common path, token-less requests made through a vulnerable application, but it is not complete protection. An attacker with code execution on the instance can still request a token. Combine IMDSv2 with a least-privilege instance role, a hop limit of 1 where possible, and fixing the application flaw that allowed the request.

Should I disable SSH on EC2 entirely?

Where Session Manager covers your needs, yes: closing port 22 removes a whole class of exposure and the key management that comes with it. Some tooling and break-glass procedures still rely on SSH. In that case, restrict the source range tightly, use short-lived keys, and log access so that SSH is an exception you can see.

Does EBS encryption by default encrypt existing volumes?

No. AWS states that encryption by default has no effect on existing EBS volumes or snapshots. It only applies to new volumes and snapshot copies created after you enable it, and only in the Region where you enabled it. Existing unencrypted volumes must be migrated, usually through an encrypted snapshot copy.

The short version

Require IMDSv2, log in through Session Manager, encrypt EBS by default in every Region, give instances small roles, patch on a fixed model, and keep instances off the public internet. Then check continuously, because one new instance launched from an old template undoes the work.

Assess your cloud security posture with ResilientX UEM — book a demo and see every EC2 misconfiguration across your accounts in one view.

One platform for your entire exposure
Explore Unified Exposure Management →