EC2 hardening checklist

28 October 2026 · 7 MIN READ

My EC2 hardening checklist for production Linux

A repeatable baseline for production Linux servers: access, firewall, web server, TLS, and a verification pass before you call it done.

Start with access, not tooling

Everything on the server becomes easier to reason about once access is boring: one dedicated user, key-only login, no root, no passwords.

Do this before installing anything else. Every later step assumes you know exactly who can reach the box and how.

sshd_config · representative excerpt
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers deploy

Two layers of firewall

Cloud security groups and an on-host firewall are not duplicates; they protect against different mistakes. The security group is the outer boundary you control in AWS. UFW is what the server itself expects, and it stays correct even when the instance moves.

Keep them consistent on purpose: write down the intended access first, then apply the same rules to both layers. Ports that exist in only one of the two are how “temporary” openings survive for a year.

ufw · baseline rules
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

Harden the web server

Most of the Nginx work is saying less: no version banner, explicit content-type handling, a strict referrer policy, and an HTTPS redirect that leaves nothing behind on port 80.

None of this is exotic. It is a short list, applied the same way on every server, which is exactly why it belongs in a checklist rather than in memory.

nginx.conf · representative directives
server_tokens off;

add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

TLS that renews itself

Certificates expire on a schedule you do not control, so renewal cannot depend on a person remembering. A small Bash script that renews and reloads, plus a scheduled run, turns a future outage into a non-event.

The first time a certificate renews without anyone touching it, the script has paid for the half hour it took to write.

Verify like an attacker would

The last step is checking the result from the outside, not from the terminal you configured it in:

  • Scan the host from outside: only the intended ports should answer.
  • Request password SSH login and confirm it is refused.
  • curl -I the site and read the headers: no server version, correct security headers, and HTTP redirected to HTTPS.
verification · representative commands
# What the outside world sees
curl -I https://example.com

# Headers to expect: no Server version, HSTS,
# X-Content-Type-Options, and a 301 to HTTPS

A baseline, not a one-off

Hardening is not a launch task that gets deleted afterwards. Written as a checklist, it can be applied to the next server in minutes and reviewed when assumptions change.

The principle I work by: treat security as a maintained baseline — review the required access first, apply changes in a controlled sequence, and verify access and application behavior afterward.

Alvin K Sabu ›EC2 hardening checklistMade to be explored.

alvin — bash — 80 × 24

Welcome to Alvin’s desktop.

Type help to explore. This is a browser simulation.

esc to close

Search this desktop

↑ ↓ to navigate ↵ to openesc to close

A little desktop tour

Click an app in the dock or a folder in the sidebar. The window controls work, too.

Search everything
Ctrl / ⌘ K
Open terminal
`
Overview / Projects / About / Toolbox / Contact
1 — 5
Close a dialog or menu
Esc

Pipeline Lab and Terminal are local demos. They never connect to production infrastructure.