0Pricing
Cloud & IT Cert Prep · Lesson

OS Hardening: Patching, Baseline Config, and CIS Benchmarks

Apply OS hardening techniques — disabling unnecessary services, enforcing baseline configurations, and using CIS benchmarks — to reduce attack surface.

OS Hardening: Patching, Baseline Config, and CIS Benchmarks is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is OS Hardening?

OS hardening is the process of reducing an operating system's attack surface by removing unnecessary features, applying security configurations, and keeping the system patched. A freshly installed operating system is not secure by default — it prioritizes usability, enabling services and features that many users might want but that most enterprise servers do not need. Every enabled service, open port, and default credential is a potential entry point for attackers. Hardening systematically closes these entry points before a system enters production.

Patch Management

Patch management is the process of identifying, testing, and applying software updates that fix security vulnerabilities. An unpatched system is one of the most exploitable targets — many major breaches (Equifax 2017, WannaCry 2017) exploited known, already-patched vulnerabilities that organizations simply had not applied. A mature patch management process defines: patch identification (subscribe to vendor advisories, CVE feeds), criticality classification (Emergency/Critical/High/Medium), testing timelines (critical patches within 48-72 hours in many frameworks), and deployment verification.

# Patch criticality SLA example
CVSS Score     SLA           Notes
----------     ----------    ----------------------
9.0 - 10.0     48 hours      Emergency patch cycle
7.0 - 8.9      7 days        Critical patch cycle
4.0 - 6.9      30 days       Standard patch cycle
0.1 - 3.9      90 days       Routine patch cycle

# Verify patch application:
# Windows: Get-HotFix | Where-Object {$_.HotFixID -eq 'KB5023706'}
# Linux:   dpkg -l | grep package_name

Disabling Unnecessary Services

Every running service is a potential attack vector. OS hardening starts with a service audit: list all running services, identify their purpose, and disable any that are not required for the system's role. On Windows Server, roles like Print Spooler, Remote Registry, and LLMNR are frequently disabled on servers that do not need them. On Linux, services like rpcbind, cups (printing), and avahi (mDNS) are typical candidates. The principle is: if you do not need it, disable it.

# Windows: disable unnecessary service
SC config 'Spooler' start= disabled
SC stop 'Spooler'

# Linux: disable unused services
systemctl disable cups
systemctl stop cups
systemctl disable avahi-daemon
systemctl stop avahi-daemon

# Verify no unnecessary ports are listening:
ss -tulnp  # Linux
netstat -an | findstr LISTENING  # Windows

Removing Unnecessary Software

Installed software that is not used represents unnecessary risk. Every package introduces potential vulnerabilities — even well-maintained software has CVEs. OS hardening includes: removing language runtimes not required by applications (Python, Perl, Ruby on web servers), removing development tools (compilers, debuggers on production systems), and removing default application packages that ship with OS images (FTP servers, telnet clients, SNMP agents). Container images should use minimal base images (Alpine, scratch, distroless) for the same reason.

# Remove unused packages (Debian/Ubuntu)
apt purge telnet ftp netcat python2 perl
apt autoremove

# Remove unused packages (RHEL/CentOS)
yum remove telnet ftp nmap-ncat

# Check what is installed:
dpkg -l | grep -i 'telnet\|ftp\|netcat'

Securing Default Accounts

Default accounts with known usernames and passwords are among the first things attackers try. Hardening steps: disable the built-in Administrator account (Windows) and rename it if disabled is not possible; rename the root account or restrict root SSH login (Linux); change all default passwords on appliances, databases, and applications before they reach production; remove guest accounts; and disable service accounts that do not require interactive login. A scan tool like Nessus will flag default credentials as critical findings.

# Linux: disable root SSH login
# Edit /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
AllowUsers admin_user service_user

# Restart SSH:
systemctl restart sshd

# Windows: disable built-in Administrator
net user Administrator /active:no

# Rename (via Group Policy):
# Computer Config > Windows Settings > Security Settings
# > Local Policies > Security Options
# > 'Accounts: Rename administrator account'

File System Permissions and Least Privilege

Secure file system permissions enforce least privilege on the OS. Web server processes should not have write access to the directories they serve. Application accounts should not have read access to configuration files containing credentials. On Linux, setuid and setgid binaries should be audited because they run with elevated privileges regardless of who executes them. On Windows, NTFS permissions and DACL auditing ensure that sensitive directories (SAM hive, shadow copies, credential stores) are accessible only to authorized processes.

# Find setuid/setgid binaries (Linux)
find / -perm /4000 -o -perm /2000 2>/dev/null

# Secure web root permissions
chown -R root:www-data /var/www/html
chmod -R 755 /var/www/html
chmod 640 /var/www/html/config.php

# Check overly permissive files
find /etc -perm -o+w 2>/dev/null  # world-writable in /etc

CIS Benchmarks

CIS Benchmarks are free, community-developed hardening guides for specific operating systems, applications, and cloud platforms. Each benchmark contains hundreds of specific configuration recommendations with rationale, remediation steps, and audit commands. CIS Benchmarks use two profile levels: Level 1 — basic, broadly applicable configurations that do not restrict functionality; Level 2 — advanced configurations for high-security environments that may impact usability. Benchmarks exist for Windows Server, Ubuntu/RHEL, macOS, Docker, Kubernetes, AWS, Azure, GCP, browsers, and databases.

# CIS Benchmark check example (Linux L1)
# CIS Ubuntu 22.04 - 1.1.1.1 Disable cramfs
modprobe -n -v cramfs 2>&1 | grep -q 'Module cramfs not found'
# Expected: Module cramfs not found OR 'install /bin/false'

# Remediate:
echo 'install cramfs /bin/false' >> /etc/modprobe.d/CIS.conf

# CIS Windows - Account Lockout threshold
# secedit /export /cfg secpol.txt
# Check: LockoutBadCount = 5 (not 0)

Baseline Configuration Management

A security baseline is a documented set of configuration settings that every system in a role category must meet. Baselines are applied via Group Policy Objects (GPOs) on Windows, Ansible playbooks, Chef cookbooks, or Puppet manifests on Linux. Configuration management tools enable drift detection: if a system deviates from the approved baseline (e.g., a service is re-enabled), automated alerts and auto-remediation can bring it back into compliance. NIST SP 800-128 provides guidance on security-focused configuration management for federal systems.

# Ansible hardening playbook snippet
- name: Disable ICMP redirects
  sysctl:
    name: net.ipv4.conf.all.accept_redirects
    value: '0'
    state: present
    reload: yes

- name: Enable address space layout randomization
  sysctl:
    name: kernel.randomize_va_space
    value: '2'
    state: present
    reload: yes

Audit Logging and Monitoring

Hardening is not just about prevention — logging and monitoring are equally important. Configure audit policies to capture: authentication events (success and failure), privilege escalation, object access (sensitive file reads), process creation (with command-line arguments), and network connection events. Logs must be forwarded to a centralized SIEM in near-real time so that local attackers with admin rights cannot cover tracks by clearing event logs. Retain logs for at least 12 months per most compliance frameworks.

# Enable Windows audit policy (Group Policy)
auditpol /set /category:'Logon/Logoff' /success:enable /failure:enable
auditpol /set /category:'Process Creation' /success:enable
auditpol /set /subcategory:'Privilege Use' /success:enable /failure:enable

# Linux: configure auditd for privilege use
echo '-a always,exit -F arch=b64 -S execve -k exec_track' >> /etc/audit/rules.d/audit.rules
echo '-w /etc/sudoers -p wa -k priv_change' >> /etc/audit/rules.d/audit.rules
augenrules --load

Automated Compliance Scanning

Manual verification of hardening benchmarks on every system is impractical at scale. Compliance scanning tools automate this check. OpenSCAP (open source) applies SCAP content to Linux systems and generates HTML reports showing passed, failed, and not-applicable checks. Nessus includes CIS benchmark policies. Microsoft Security Compliance Toolkit evaluates Windows systems against Microsoft baselines. These tools are run on a regular schedule (weekly or monthly) and deviations trigger remediation tickets in the change management system.

# OpenSCAP compliance scan (RHEL/CentOS)
oscap xccdf eval \
  --profile xccdf_org.ssgproject.content_profile_cis \
  --results results.xml \
  --report report.html \
  /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml

# Generate remediation script
oscap xccdf generate fix \
  --fix-type bash \
  --result-id '' \
  results.xml > remediation.sh

Group Policy and Security Templates

On Windows domains, Group Policy Objects (GPOs) are the primary mechanism for applying and enforcing security baselines at scale. Security templates (pre-built or custom .inf files) can be imported into GPOs to configure hundreds of settings simultaneously: account policy, audit policy, user rights assignment, security options, and registry values. The Security Configuration and Analysis snap-in and secedit command-line tool compare current settings against a defined template and generate compliance reports. GPOs apply at startup and at regular intervals, ensuring drift from baseline is automatically corrected.

# Apply security template via secedit
secedit /configure /db %windir%\security\local.sdb \
  /cfg C:\Templates\CIS_Level1_Server2022.inf \
  /log secedit_apply.log

# Analyze current config vs template
secedit /analyze /db %windir%\security\local.sdb \
  /cfg C:\Templates\CIS_Level1_Server2022.inf \
  /log secedit_analysis.log

# View result: settings marked as compliant or non-compliant

Quick Check

Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.

Lesson Recap

In this lesson you learned: OS hardening reduces attack surface by disabling services, removing software, securing accounts, and applying least-privilege permissions, patch management closes known vulnerabilities with criticality-based SLAs, and CIS Benchmarks provide Level 1 (basic) and Level 2 (advanced) configuration guidance enforced through automated compliance scanning tools. Next up we explore Mobile Device Management and BYOD policies.

Frequently asked questions

Is the “OS Hardening: Patching, Baseline Config, and CIS Benchmarks” lesson free?

Yes — the full text of “OS Hardening: Patching, Baseline Config, and CIS Benchmarks” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.

What will I learn in “OS Hardening: Patching, Baseline Config, and CIS Benchmarks”?

Apply OS hardening techniques — disabling unnecessary services, enforcing baseline configurations, and using CIS benchmarks — to reduce attack surface. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cloud & IT Cert Prep?

No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “OS Hardening: Patching, Baseline Config, and CIS Benchmarks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cloud & IT Cert Prep lesson?

Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Antivirus, EDR, and XDR Platforms
  2. OS Hardening: Patching, Baseline Config, and CIS Benchmarks
  3. Mobile Device Management (MDM) and BYOD Policies
  4. Host-Based Firewall and Application Allowlisting
← Back to Cloud & IT Cert Prep