Skip to content

Lesson 08 — EC2 Hardening & Patch Management

Learning Path

☁️ Phase 2 – AWS Cloud Security

📘 Module 05 – Amazon EC2 Security


By the end of this lesson, you will be able to:

  • Understand EC2 hardening principles.
  • Reduce the attack surface of EC2 instances.
  • Apply secure operating system configurations.
  • Manage operating system patches.
  • Use AWS Systems Manager Patch Manager.
  • Verify system compliance.
  • Apply enterprise hardening standards.

📚 Lesson Information

Estimated Time: 3 Hours

Difficulty: Intermediate

Prerequisites: Lesson 07 – AWS Systems Manager & Session Manager

Hands-on Lab: Yes


CloudNova Technologies has successfully deployed hundreds of EC2 instances.

A recent internal security assessment found several issues:

  • Operating systems not fully updated.
  • Unnecessary software installed.
  • SSH still enabled on some servers.
  • Weak password policies.
  • Missing security patches.
  • Unused services running.

Although no compromise occurred, these weaknesses increased the organisation’s attack surface.

The Cloud Security team has been tasked with hardening every EC2 instance and implementing automated patch management.


EC2 hardening is the process of reducing the attack surface of an EC2 instance by applying secure configurations and removing unnecessary risks.

The objective is simple:

Only run what is required. Only allow who is authorised. Continuously keep the system updated.


CloudNova follows a layered security approach.

IAM
Security Groups
Amazon VPC
Hardened EC2 Instance
Operating System
Installed Services
Applications & Data

Security should never rely on a single control.


A secure EC2 instance includes:

  • Updated operating system
  • Latest security patches
  • Least privilege access
  • Minimal installed packages
  • Host firewall configuration
  • Secure SSH configuration (or Session Manager)
  • Logging enabled
  • Malware protection (where required)
  • File integrity monitoring
  • Secure user management

Every production server must comply with the following standards.

Security Control Status
Latest OS Updates
EBS Encryption
IAM Role Attached
Session Manager Enabled
CloudWatch Agent Installed
Public IP Disabled
Root Login Disabled
Unused Services Removed
Logging Enabled
Security Groups Reviewed

Operating systems continuously receive:

  • Security patches
  • Kernel updates
  • Bug fixes
  • Performance improvements

Delaying updates increases the risk of exploitation.

Example:

Known Vulnerability
Public Exploit Released
Unpatched Server
Compromise

Every installed application increases the attack surface.

Example:

Instead of:

Web Server
FTP Server
Mail Server
Database
Development Tools
Games

Only install:

Web Server
Monitoring Agent
Required Libraries

Minimal systems are easier to secure.


View running services:

Terminal window
systemctl list-units --type=service

Disable services that are not required.

Example:

Terminal window
sudo systemctl disable telnet
Terminal window
sudo systemctl stop telnet

Never disable services without understanding their purpose.


CloudNova standards:

  • No shared administrator accounts.
  • Individual administrator access.
  • Least privilege permissions.
  • Multi-Factor Authentication (MFA) for AWS identities.
  • Session Manager preferred over SSH.

Review local users:

Terminal window
cat /etc/passwd

Review groups:

Terminal window
cat /etc/group

If SSH is required:

  • Disable root login.
  • Disable password authentication.
  • Use key-based authentication.
  • Restrict source IP addresses.
  • Monitor login attempts.

Example:

PermitRootLogin no
PasswordAuthentication no

Where possible, CloudNova uses AWS Systems Manager Session Manager instead of SSH.


A hardened server generates logs.

CloudNova forwards logs to:

  • Amazon CloudWatch
  • AWS CloudTrail (for AWS API activity)
  • Security Information and Event Management (SIEM) platform (where implemented)

Common Linux log locations:

/var/log/messages
/var/log/secure
/var/log/syslog

Patch management is the process of identifying, testing and installing software updates.

Updates include:

  • Security fixes
  • Bug fixes
  • Kernel updates
  • Operating system improvements

Patching reduces exposure to known vulnerabilities.


Identify Updates
Test
Approve
Deploy
Verify
Report

CloudNova follows this lifecycle for all production systems.


Patch Manager automates operating system patching.

Capabilities include:

  • Scan instances
  • Install updates
  • Compliance reporting
  • Scheduled maintenance
  • Patch baselines

This reduces manual effort and improves consistency.


Cloud Engineer
Systems Manager
Patch Manager
Managed EC2 Instances
Compliance Report

A Patch Baseline defines which updates are approved.

Example:

Critical Updates
Approved
Security Updates
Approved
Optional Packages
Manual Review

Patch Baselines help organisations control update deployment.


CloudNova patches production servers during approved maintenance windows.

Example:

Sunday
02:00 AM
Patch Installation
Server Reboot
Health Check
Production Ready

This minimises disruption to business operations.


🛠 Lab 01 — Check for Available Updates

Section titled “🛠 Lab 01 — Check for Available Updates”

Connect to the EC2 instance using Session Manager.

Run:

Terminal window
sudo dnf check-update

or

Terminal window
sudo yum check-update

depending on the operating system.

Review the available updates.


🛠 Lab 02 — Apply Operating System Updates

Section titled “🛠 Lab 02 — Apply Operating System Updates”

Run:

Terminal window
sudo dnf update -y

or

Terminal window
sudo yum update -y

Verify that the update completes successfully.


Run:

Terminal window
cat /etc/os-release

Check:

Terminal window
uname -r

Review the current kernel version.


Run:

Terminal window
systemctl list-units --type=service

Identify:

  • Required services
  • Optional services
  • Unused services

Document which services could be disabled after change approval.


Navigate to:

AWS Console
Systems Manager
Patch Manager
Patch Baselines

Review the default patch baseline.

If appropriate for your lab environment, create a custom baseline for Amazon Linux.


Navigate to:

Systems Manager
Patch Manager
Managed Nodes

Run a compliance scan.

Review:

  • Missing updates
  • Installed updates
  • Compliance status

Use Systems Manager Run Command.

Select:

AWS-RunPatchBaseline

Operation:

Scan

Review the results.

Then perform:

Install

Verify successful patch installation.


Terminal window
aws ssm describe-instance-information

Terminal window
aws ssm describe-patch-baselines

Terminal window
aws ssm send-command \
--document-name AWS-RunPatchBaseline \
--parameters Operation=Scan \
--instance-ids i-xxxxxxxx

Terminal window
aws ssm send-command \
--document-name AWS-RunPatchBaseline \
--parameters Operation=Install \
--instance-ids i-xxxxxxxx

Terminal window
aws ssm list-command-invocations \
--details

Verify:

✔ Operating system updated.

✔ Latest approved security patches installed.

✔ Systems Manager reports the instance as compliant.

✔ SSM Agent running.

✔ Unnecessary services identified.

✔ CloudWatch Agent operational.

✔ IAM Role attached.

✔ Session Manager functioning correctly.


Patch scan fails.

Check:

  • SSM Agent status.
  • IAM Role permissions.
  • Managed Node registration.
  • Network connectivity.

Updates cannot be installed.

Verify:

  • Internet or repository access.
  • Package manager configuration.
  • Disk space availability.

Managed Node not compliant.

Review:

  • Patch Baseline.
  • Pending reboot.
  • Missing approved updates.

Kernel updated but old version still active.

The instance may require a reboot.

Run:

Terminal window
sudo reboot

Reconnect using Session Manager and verify the new kernel version.


CloudNova standards:

  • Enable automatic security updates where appropriate.
  • Use Systems Manager Patch Manager for scheduling and compliance.
  • Test updates in development before production.
  • Use Maintenance Windows for production patching.
  • Remove unnecessary software packages.
  • Review running services regularly.
  • Disable unused accounts.
  • Monitor patch compliance continuously.
  • Document exceptions requiring delayed patching.

❌ Never patching production servers.

❌ Installing patches without testing.

❌ Leaving unsupported operating systems in production.

❌ Running unnecessary services.

❌ Leaving SSH open when Session Manager is available.

❌ Ignoring compliance reports.

❌ Delaying critical security updates without risk assessment.


Harden a new EC2 instance.

Requirements:

  • Amazon Linux 2023
  • Private Subnet
  • Session Manager enabled
  • IAM Role attached
  • CloudWatch Agent installed
  • Encrypted EBS volume

Tasks:

  1. Apply all available operating system updates.
  2. Review running services and identify unnecessary ones.
  3. Verify SSH configuration (or document why Session Manager replaces SSH).
  4. Run a Patch Manager compliance scan.
  5. Install approved patches.
  6. Reboot the instance if required.
  7. Verify the system is compliant.

Capture screenshots of:

  • Systems Manager Managed Nodes
  • Patch Manager Compliance
  • Run Command Results
  • Updated Operating System
  • Running Services
  • AWS CLI outputs

  1. What is EC2 hardening?
  2. Why is reducing the attack surface important?
  3. What is the purpose of Patch Manager?
  4. What is a Patch Baseline?
  5. Why are Maintenance Windows used?
  6. Why should unnecessary services be removed?
  7. How does Session Manager contribute to hardening?
  8. Which AWS Systems Manager document is commonly used for patch operations?
  9. Why should updates be tested before production deployment?
  10. How does regular patching improve the security posture of an organisation?

After completing this lesson, you should understand:

  • EC2 hardening is an ongoing process that reduces the attack surface through secure configuration, least privilege and continuous maintenance.
  • Regular operating system updates and timely security patching protect EC2 instances from known vulnerabilities.
  • AWS Systems Manager Patch Manager automates patch scanning, installation and compliance reporting across large fleets.
  • Enterprise environments benefit from standardised patch baselines, maintenance windows and documented hardening procedures.
  • Combining secure configuration, automated patching and continuous monitoring creates resilient and well-managed EC2 workloads.

➡️ Lesson 09 — Monitoring, Logging & Backup