Linux · Lesson 9 of 10 · 4 min read
Security hardening and fleet operations
Hardening a Linux server
A checklist you can talk through:
- Patch — automatic security updates (
unattended-upgrades,dnf-automatic) or, better, immutable rebuilds from a patched AMI on a schedule. - Minimal install — remove unused packages and services; fewer listening ports (
ss -tlnpshould be short). - SSH — key-only auth (
PasswordAuthentication no), no root login (PermitRootLogin no),AllowUsers/AllowGroups, restrict source IPs in the security group. Better still, no inbound SSH at all: use SSM Session Manager (IAM-authenticated, logged to CloudWatch/S3, no open port 22, no keys to rotate). - Least privilege — services run as dedicated non-root users; narrow sudo rules; no shared accounts.
- MAC — keep SELinux/AppArmor enforcing.
- Audit and logging —
auditdrules for sensitive files, logs shipped off-box (CloudWatch agent, Fluent Bit) so attackers can't erase them. - Filesystem —
noexec,nosuid,nodevon/tmpwhere possible; correct permissions on secrets (600, owned by the service user). - Kernel — sysctl hardening (
net.ipv4.conf.all.rp_filter=1, disable IP forwarding where not needed,kernel.randomize_va_space=2). - Benchmarks — measure against CIS benchmarks; AWS Inspector scans EC2 for CVEs.
- Secrets — never in shell history, scripts or user data in plain text; fetch from Secrets Manager/SSM Parameter Store at runtime.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Package management
| Family | Low-level | High-level | Examples |
|---|---|---|---|
| Debian/Ubuntu | dpkg |
apt |
apt update && apt install -y nginx, apt list --upgradable |
| RHEL/Amazon Linux/Fedora | rpm |
dnf (yum on older) |
dnf install -y nginx, rpm -qf /usr/bin/curl (which package owns a file) |
| Alpine | — | apk |
apk add --no-cache curl |
Pin versions for reproducibility in images; use internal mirrors/proxies (Artifactory, Nexus) in locked-down environments.
Managing many servers without Ansible
Not every team uses a configuration management tool such as Ansible. If you haven't used one, have a strong answer ready for "how would you push a config change to 50 servers?":
- Immutable infrastructure — bake the change into the AMI (Packer or EC2 Image Builder) and roll the Auto Scaling group with an instance refresh. No drift, easy rollback.
- Launch templates and user data for bootstrap-time configuration.
- SSM Run Command / State Manager — run a document across instances selected by tags, with rate control and error thresholds, output logged to S3. State Manager reapplies periodically to fix drift.
- SSM Patch Manager for OS patching windows.
- For Kubernetes nodes, you rarely touch nodes at all — replace them (Karpenter drift / node group updates).
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Then add honestly: "Ansible does the same push-based configuration over SSH with idempotent modules; the concepts — inventory, idempotency, roles — map directly, and I'd ramp up quickly."
Time, logs and certificates
- Keep clocks synced (
chronyd; on AWS the Amazon Time Sync Service at 169.254.169.123). Clock skew breaks TLS validation, AWS request signing ("Signature expired"), JWTs and distributed logs. - Centralise logs and include host, service and request IDs.
- Trust store: CA certificates live in
/etc/ssl/certs//etc/pki/ca-trust; add a corporate CA withupdate-ca-certificates(Debian) orupdate-ca-trust(RHEL).