Lab 02 — Linux Hardening
In the previous lab, you learned how to administer a Linux server.
Now you will move from:
Functional Linux Serverto:
Hardened Linux ServerLinux hardening is the process of reducing unnecessary attack surface while preserving the business functions the system is expected to provide.
Your objective is not:
Disable EverythingYour objective is:
Understand the Server ↓Identify Required Functions ↓Remove Unnecessary Exposure ↓Apply Security Controls ↓Validate Business Function ↓Document the ResultMission Information
Section titled “Mission Information”Lab: Linux Hardening
Level: Intermediate
Estimated Time: 120–180 minutes
Environment: Authorized disposable Linux VM
Primary Role: Linux Security Engineer
Secondary Roles: Cloud Security Engineer, System Administrator, SOC Analyst, DevSecOps Engineer
Mission Scenario
Section titled “Mission Scenario”Your organization has deployed a new Linux server that will soon host an internal application.
Before the server can be approved for production use, the security team has asked you to perform a hardening review.
You must evaluate and improve:
System Baseline
Accounts
Administrative Privilege
Authentication
SSH
Filesystem Permissions
Temporary Directories
Installed Software
Running Services
Network Exposure
Host Firewall
Patching
Logging
Auditing
Time Synchronization
Security ControlsYou must also ensure that your changes do not unnecessarily break the server.
Mission Objectives
Section titled “Mission Objectives”By completing this lab, you should be able to:
- Establish a Linux security baseline
- Review local users and groups
- Identify unnecessary or privileged accounts
- Review administrative access
- Evaluate password and account settings
- Harden SSH safely
- Identify unnecessary software
- Review running services
- Reduce network attack surface
- Configure basic firewall restrictions
- Review sensitive filesystem permissions
- Identify world-writable locations
- Review SUID and SGID files
- Validate package and patch status
- Review SELinux or AppArmor
- Validate system logging
- Review auditing capabilities
- Verify time synchronization
- Produce professional security findings
- Create before-and-after hardening evidence
Lab Architecture
Section titled “Lab Architecture”+----------------------------+| Administrator || Security Engineer |+-------------+--------------+ | | SSH / Console | v+----------------------------+| Linux Lab Server || || Users & Groups || sudo || SSH || Services || Firewall || Packages || Filesystem || Logging || Security Controls |+----------------------------+Important Safety Principle
Section titled “Important Safety Principle”Hardening can break systems if performed without understanding application requirements.
For every proposed change ask:
What Does This Control Protect?
What Depends on This Setting?
What Could Break?
How Will I Validate It?
How Will I Roll Back?Recommended Lab Environment
Section titled “Recommended Lab Environment”Use your own authorized disposable Linux VM.
Suitable examples include:
Ubuntu
Debian
Rocky Linux
AlmaLinux
Red Hat Enterprise LinuxSome commands and configuration locations vary between distributions.
Where appropriate, this lab provides both Debian-family and Red Hat-family concepts.
Before You Begin
Section titled “Before You Begin”Take a VM snapshot if your virtualization platform supports it.
Record:
Snapshot Name:Pre-Linux-HardeningThis gives you a safe recovery point.
Hardening Workflow
Section titled “Hardening Workflow”Use this throughout the lab:
BASELINE ↓REVIEW ↓PRIORITIZE ↓CHANGE ↓VALIDATE ↓DOCUMENTPart 01 — Establish the Baseline
Section titled “Part 01 — Establish the Baseline”Do not begin changing settings immediately.
First understand the current system.
Step 01 — Confirm Identity
Section titled “Step 01 — Confirm Identity”Run:
whoamiThen:
idRecord:
Current User:
UID:
Groups:
Administrative Access:Step 02 — Identify the System
Section titled “Step 02 — Identify the System”Run:
hostnamecat /etc/os-releaseuname -ruptimeRecord:
Hostname:
Distribution:
Version:
Kernel:
Uptime:Step 03 — Create a Hardening Workspace
Section titled “Step 03 — Create a Hardening Workspace”Create:
mkdir -p ~/linux-hardening-labEnter it:
cd ~/linux-hardening-labCreate folders:
mkdir baseline findings evidenceStep 04 — Capture System Information
Section titled “Step 04 — Capture System Information”Create:
{ echo "Linux Hardening Baseline" echo "========================" echo "Date: $(date)" echo "Hostname: $(hostname)" echo "Kernel: $(uname -r)" echo "Current User: $(whoami)"} > baseline/system-info.txtReview:
cat baseline/system-info.txtBaseline Principle
Section titled “Baseline Principle”A professional hardening exercise should preserve:
Before Stateand:
After StateThis helps demonstrate:
What Changed?
Why?
Did It Work?Part 02 — Review Local Accounts
Section titled “Part 02 — Review Local Accounts”Identity is one of the most important Linux security areas.
Start with:
getent passwdStep 05 — Understand Account Types
Section titled “Step 05 — Understand Account Types”Linux systems commonly contain:
Human Users
Administrative Users
Service Accounts
System AccountsDo not assume every unfamiliar account is malicious.
Many are required by installed software.
Step 06 — Identify Interactive Shell Accounts
Section titled “Step 06 — Identify Interactive Shell Accounts”Review:
getent passwd | grep -E '/bin/(bash|sh|zsh|fish)$'The exact shells present depend on the system.
Ask:
Which Accounts Can Log In Interactively?Step 07 — Review UID 0 Accounts
Section titled “Step 07 — Review UID 0 Accounts”Run:
awk -F: '$3 == 0 {print $1 ":" $3 ":" $7}' /etc/passwdNormally, highly privileged UID 0 accounts require strict review.
Document any unexpected results.
Security Question
Section titled “Security Question”Ask:
Should Any AccountBesides the ApprovedAdministrative IdentityHave UID 0?Step 08 — Review Login Shells
Section titled “Step 08 — Review Login Shells”Accounts that do not require interactive login may use shells such as:
/usr/sbin/nologinor:
/sbin/nologindepending on the distribution.
The principle is:
No Interactive Requirement ↓No Interactive Shellwhere operationally appropriate.
Step 09 — Review Account Ownership
Section titled “Step 09 — Review Account Ownership”For every human account ask:
Who Owns It?
Why Does It Exist?
Is the User Still Active?
Which Groups Does It Belong To?
Does It Need Administrative Access?Account Review Table
Section titled “Account Review Table”Create documentation like:
| Account | Type | Interactive Login | Privileged | Required |
|---|---|---|---|---|
| user1 | Human | Yes | No | Yes |
| service1 | Service | No | No | Yes |
| olduser | Human | Yes | Unknown | Review |
Do not remove real accounts without authorization.
Part 03 — Review Groups
Section titled “Part 03 — Review Groups”Run:
getent groupLook especially for groups that may grant elevated capabilities.
Examples depend on distribution, but may include administrative groups.
Step 10 — Review Your Administrative Group
Section titled “Step 10 — Review Your Administrative Group”Run:
idThen review the relevant administrative group using:
getent group <group-name>Security Principle
Section titled “Security Principle”Group Membership ↓PrivilegeTherefore group membership is security-sensitive.
Part 04 — Review sudo Access
Section titled “Part 04 — Review sudo Access”Administrative privilege should follow:
Least PrivilegeUse:
sudo -lto review the privileges of your current account.
Step 11 — Review sudo Configuration
Section titled “Step 11 — Review sudo Configuration”Where authorized, inspect configuration carefully.
Main locations may include:
/etc/sudoers
/etc/sudoers.d/Use safe inspection methods.
Do not edit /etc/sudoers directly with an ordinary text editor.
Use the approved validation workflow such as:
sudo visudowhen legitimate changes are required.
Security Questions
Section titled “Security Questions”Ask:
Who Can Use sudo?
What Can They Run?
Can They Run Everything?
Is That Required?
Is Access Documented?Finding Example
Section titled “Finding Example”Finding:Excessive Administrative Privilege
Observation:A user has broad sudo access withouta documented administrative requirement.
Risk:Compromise of the account could providefull control of the Linux server.
Recommendation:Restrict privileged access to theminimum administrative functionsrequired for the user's role.Part 05 — Review Password and Account Controls
Section titled “Part 05 — Review Password and Account Controls”Password-related configuration differs by distribution and enterprise authentication model.
Review relevant account-aging information using:
chage -l <authorized-test-user>Step 12 — Review Password Aging Concepts
Section titled “Step 12 — Review Password Aging Concepts”Understand:
Minimum Password Age
Maximum Password Age
Expiration Warning
Account ExpirationDo not blindly apply arbitrary expiry settings.
Align with:
Organization Policy
Authentication Architecture
Regulatory RequirementsStep 13 — Review Locked Accounts
Section titled “Step 13 — Review Locked Accounts”For training identities you control, understand the difference between:
Disable Interactive Access
Lock Password Authentication
Delete AccountDeletion is not always the correct security response.
During investigations, preserving the account may be necessary.
Part 06 — Review SSH Configuration
Section titled “Part 06 — Review SSH Configuration”SSH is one of the most important Linux remote-access services.
First determine whether SSH is running.
Possible service names include:
ssh
sshdCheck the correct service for your distribution.
Example:
systemctl status sshdor:
systemctl status sshStep 14 — Locate SSH Configuration
Section titled “Step 14 — Locate SSH Configuration”The primary server configuration is commonly:
/etc/ssh/sshd_configAdditional configuration fragments may exist depending on the distribution.
Before changing anything, create an authorized backup:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.lab-backupStep 15 — Review Effective SSH Configuration
Section titled “Step 15 — Review Effective SSH Configuration”Where supported:
sudo sshd -TThis is often more useful than reading only one configuration file because it can show effective settings.
SSH Hardening Questions
Section titled “SSH Hardening Questions”Review:
Is Direct Root Login Required?
Which Authentication Methods Are Allowed?
Are Empty Passwords Allowed?
Which Users/Groups Can Connect?
Is SSH Exposed to the Correct Networks?
Are Logs Available?Step 16 — Root SSH Login
Section titled “Step 16 — Root SSH Login”A common security objective is:
Prevent Direct Remote Root Loginwhere administrative workflows permit it.
A common configuration consideration is:
PermitRootLoginDo not change it blindly.
First ensure:
A Working Administrative Account Exists
sudo Works
Your Current Session Remains Open
Recovery Access ExistsCritical Safety Rule
Section titled “Critical Safety Rule”Never close your current working SSH session immediately after changing remote-access configuration.
Use:
Existing Session ↓Apply Change ↓Validate Configuration ↓Reload Service ↓Open Second Session ↓Confirm Access ↓Only Then Close Original SessionStep 17 — Validate SSH Configuration
Section titled “Step 17 — Validate SSH Configuration”Before reload or restart, use the platform’s supported syntax validation where available:
sudo sshd -tNo output normally indicates that no syntax problem was detected.
Always confirm behavior on your system.
Step 18 — Authentication Methods
Section titled “Step 18 — Authentication Methods”Organizations may prefer:
SSH Keys
Central Identity
MFA-Integrated Accessover unmanaged password-only administrative access.
The correct configuration depends on your environment.
Do not disable a working authentication method until the replacement has been validated.
Step 19 — Restrict SSH Access
Section titled “Step 19 — Restrict SSH Access”SSH exposure may be restricted using several layers:
Cloud Firewall
Network Firewall
Host Firewall
SSH User/Group RulesThink:
Who Needs Access? ↓From Which Network? ↓Using Which Identity?Part 07 — Review SSH Keys
Section titled “Part 07 — Review SSH Keys”For authorized users, SSH public keys may be stored under locations such as:
~/.ssh/authorized_keysSecurity Review
Section titled “Security Review”Ask:
Who Owns This Key?
Is It Still Required?
When Was It Issued?
Is It Shared?
Can It Be Revoked?
Does the File Have Appropriate Permissions?Important
Section titled “Important”Never copy private SSH keys into:
Reports
Tickets
Chat
Source RepositoriesPart 08 — Review Installed Software
Section titled “Part 08 — Review Installed Software”More installed software generally means:
More Code
More Vulnerabilities
More Patches
More Attack SurfaceStep 20 — Inventory Packages
Section titled “Step 20 — Inventory Packages”Debian family:
dpkg -lRPM family:
rpm -qaSave package inventory if appropriate.
Example on RPM systems:
rpm -qa | sort > baseline/packages.txtExample on Debian systems:
dpkg-query -W > baseline/packages.txtStep 21 — Identify Unnecessary Software
Section titled “Step 21 — Identify Unnecessary Software”Do not remove packages simply because you do not recognize them.
For each questionable package determine:
Purpose
Dependency
Application Owner
Support Requirement
Security ImpactPrinciple
Section titled “Principle”Required Software ↓Keep + Maintain
Unnecessary Software ↓Review for RemovalPart 09 — Review Running Services
Section titled “Part 09 — Review Running Services”Run:
systemctl --type=service --state=runningCreate an inventory.
Ask for each service:
What Is It?
Why Is It Running?
Does the Application Need It?
Does It Listen on a Network Port?
Should It Start Automatically?Step 22 — Review Enabled Services
Section titled “Step 22 — Review Enabled Services”Where appropriate:
systemctl list-unit-files --type=service --state=enabledRemember:
Runningand:
Enabled at Bootare different conditions.
Service Review Table
Section titled “Service Review Table”| Service | Running | Enabled | Network Exposed | Required |
|---|---|---|---|---|
| SSH | Yes | Yes | Yes | Yes |
| Example Service | Yes | Yes | Yes | Review |
Part 10 — Reduce Unnecessary Services
Section titled “Part 10 — Reduce Unnecessary Services”If a harmless lab service is clearly unnecessary and you are authorized to modify it, use the appropriate service-management workflow.
Conceptually:
Confirm Not Required ↓Stop ↓Disable ↓ValidateDo not disable services merely to satisfy a checklist.
Finding Example
Section titled “Finding Example”Finding:Unnecessary Service Enabled
Observation:A service without a confirmed businessrequirement is running and configuredto start automatically.
Risk:The service increases operating-systemattack surface and patch-management burden.
Recommendation:Confirm service ownership and disableor remove the service if it is not required.Part 11 — Review Listening Ports
Section titled “Part 11 — Review Listening Ports”Run:
sudo ss -lntupDocument:
Protocol
Address
Port
Process
Expected?Example Mental Model
Section titled “Example Mental Model”0.0.0.0:PORTmay indicate broader IPv4 listening exposure than:
127.0.0.1:PORTdepending on the application.
Similarly, review IPv6 bindings.
Security Question
Section titled “Security Question”For every listening socket ask:
Should This ServiceListen on This Interface?Part 12 — Map Ports to Business Requirements
Section titled “Part 12 — Map Ports to Business Requirements”Create:
| Port | Service | Bound Address | Required | Expected Source |
|---|---|---|---|---|
| 22 | SSH | Example | Yes | Admin Network |
| 443 | Application | Example | Yes | Approved Users |
| Unknown | Unknown | Example | Review | Unknown |
This transforms:
Port Scan Datainto:
Security ContextPart 13 — Review Host Firewall
Section titled “Part 13 — Review Host Firewall”Different Linux distributions use different firewall-management layers.
Common environments may include:
firewalld
nftables
ufwDetermine what your server uses before making changes.
Step 23 — Check Firewalld
Section titled “Step 23 — Check Firewalld”If installed:
sudo firewall-cmd --stateThen:
sudo firewall-cmd --get-active-zonesReview active rules:
sudo firewall-cmd --list-allStep 24 — Check UFW
Section titled “Step 24 — Check UFW”If the system uses UFW:
sudo ufw status verboseFirewall Principle
Section titled “Firewall Principle”Your desired state is:
Required Traffic ↓Allowed
Unnecessary Traffic ↓RestrictedCritical Remote Access Warning
Section titled “Critical Remote Access Warning”If you are connected through SSH:
DO NOTEnable a restrictive firewall policybefore ensuring your approved SSH accesswill remain allowed.Otherwise you may lock yourself out.
Part 14 — Firewall Validation
Section titled “Part 14 — Firewall Validation”After approved firewall changes validate:
SSH Still Works
Application Works
Required Port Accessible
Unnecessary Port RestrictedUse a second connection/session where practical.
Part 15 — Review File Permissions
Section titled “Part 15 — Review File Permissions”Focus on sensitive locations such as:
/etc
/root
User SSH Directories
Application Configuration
Secrets Locations
Service ConfigurationStep 25 — Review /etc/passwd
Section titled “Step 25 — Review /etc/passwd”ls -l /etc/passwdStep 26 — Review /etc/shadow
Section titled “Step 26 — Review /etc/shadow”Use:
sudo ls -l /etc/shadowDo not display or copy password-hash contents into your report.
Your goal is to review:
Owner
Group
Permissionsnot secret material.
Part 16 — Find World-Writable Files
Section titled “Part 16 — Find World-Writable Files”World-writable files can create security concerns depending on their purpose.
In your lab, perform a controlled review of the local filesystem.
One approach is:
sudo find / -xdev -type f -perm -0002 -print 2>/dev/nullReview results carefully.
Do not assume every result is automatically a vulnerability.
Step 27 — Review World-Writable Directories
Section titled “Step 27 — Review World-Writable Directories”Conceptually, inspect directories writable by broad user populations.
Pay particular attention to:
Ownership
Sticky Bit
Business PurposeShared temporary directories often require specialized permission models.
Part 17 — /tmp Security
Section titled “Part 17 — /tmp Security”Check:
ls -ld /tmpOn many systems you may see permissions conceptually similar to:
drwxrwxrwtThe final:
trepresents the sticky bit.
Sticky Bit Purpose
Section titled “Sticky Bit Purpose”In a shared directory:
Many Users Can Create Filesbut the sticky bit helps prevent users from deleting files owned by other users.
Part 18 — Review SUID Files
Section titled “Part 18 — Review SUID Files”SUID can allow executables to operate with the effective identity of the file owner.
Inventory SUID files in your lab:
sudo find / -xdev -type f -perm -4000 -print 2>/dev/nullSecurity Review
Section titled “Security Review”For each unexpected entry ask:
Which Package Owns It?
Why Is SUID Required?
Is It Part of the Approved Baseline?
Is It Supported?Do not remove SUID from legitimate system binaries without understanding the impact.
Part 19 — Review SGID Files
Section titled “Part 19 — Review SGID Files”Similarly:
sudo find / -xdev -type f -perm -2000 -print 2>/dev/nullReview unexpected entries.
Security Principle
Section titled “Security Principle”Special Permission ↓Understand Purpose ↓Compare Baseline ↓Investigate DeviationPart 20 — Review Home Directory Permissions
Section titled “Part 20 — Review Home Directory Permissions”List:
ls -ld /home/*Review whether home directories expose more information than required.
Consider:
Business Requirement
Shared Environment
Data Sensitivity
Application CompatibilityPart 21 — Review SSH Directory Permissions
Section titled “Part 21 — Review SSH Directory Permissions”For your own account:
ls -ld ~/.ssh 2>/dev/nulland:
ls -l ~/.ssh 2>/dev/nullDo not expose private key contents.
Security-sensitive SSH files generally require tightly controlled ownership and permissions.
Part 22 — Review PATH
Section titled “Part 22 — Review PATH”Run:
echo "$PATH"Break the path into entries:
echo "$PATH" | tr ':' '\n'Security Review
Section titled “Security Review”Ask:
Does PATH IncludeWorld-Writable Directories?
Does It Include "."?
Can Untrusted UsersModify Earlier Directories?PATH Security Model
Section titled “PATH Security Model”Command Typed ↓PATH Search Order ↓First Matching Executable ↓ExecutedTherefore search order matters.
Part 23 — Review Package Updates
Section titled “Part 23 — Review Package Updates”Patch management is fundamental to hardening.
On Debian-family systems, approved update review may use:
sudo apt updatefollowed by an update assessment.
On Red Hat-family systems, appropriate DNF tools may be used to inspect available updates.
Important
Section titled “Important”Do not automatically patch production systems simply because updates exist.
Use:
Identify ↓Assess ↓Test ↓Approve ↓Deploy ↓ValidateStep 28 — Document Pending Security Maintenance
Section titled “Step 28 — Document Pending Security Maintenance”Record:
Packages Requiring Review:
Kernel Update Required?
Application Restart Required?
Reboot Required?
Change Window Needed?Part 24 — Review Repository Configuration
Section titled “Part 24 — Review Repository Configuration”Ensure package repositories are:
Expected
Approved
Trusted
SupportedUnknown package sources may create:
Software Supply-Chain RiskPart 25 — Review SELinux
Section titled “Part 25 — Review SELinux”On Red Hat-family systems:
getenforceand:
sestatuswhere available.
Desired Principle
Section titled “Desired Principle”If SELinux is part of the approved platform design:
Use SELinuxrather than:
Disable SELinuxBecause Something FailedStep 29 — Interpret SELinux State
Section titled “Step 29 — Interpret SELinux State”Possible states include:
Enforcing
Permissive
DisabledSecurity Meaning
Section titled “Security Meaning”Enforcing ↓Policy Applied
Permissive ↓Policy Violations Logged
Disabled ↓Policy Not ActivePart 26 — SELinux Troubleshooting
Section titled “Part 26 — SELinux Troubleshooting”If an application fails:
Application Failure ↓Traditional Permissions ↓Logs ↓SELinux Context ↓Expected Policy ↓Correct RemediationDo not simply turn off SELinux.
Part 27 — Review AppArmor
Section titled “Part 27 — Review AppArmor”On distributions using AppArmor, determine whether profiles are active using the appropriate supported tools.
Conceptually review:
Profile Loaded?
Enforcing?
Complain Mode?
Application Covered?Security Principle
Section titled “Security Principle”SELinux and AppArmor provide:
Additional Policy Layerbeyond standard discretionary permissions.
Part 28 — Review Time Synchronization
Section titled “Part 28 — Review Time Synchronization”Accurate system time is essential for:
Authentication
Logs
Incident Response
Distributed Applications
SIEM CorrelationCheck:
timedatectlLook for:
Timezone
System Clock
Synchronization StateStep 30 — Review Time Service
Section titled “Step 30 — Review Time Service”Depending on your distribution, time synchronization may use services such as:
chronyd
systemd-timesyncdConfirm the approved mechanism is healthy.
Part 29 — Review System Logging
Section titled “Part 29 — Review System Logging”Run:
journalctl -n 50Check whether:
System Events
Service Events
Authentication Events
Errorsare available.
Step 31 — Review Authentication Logs
Section titled “Step 31 — Review Authentication Logs”Distribution-dependent locations may include:
/var/log/auth.log
/var/log/secureor the system journal.
Use the appropriate source for your environment.
Step 32 — Review Log Permissions
Section titled “Step 32 — Review Log Permissions”Logs may contain sensitive information.
Inspect:
ls -ld /var/logThen review selected log-file ownership and permissions without copying sensitive content.
Part 30 — Log Retention
Section titled “Part 30 — Log Retention”Hardening is incomplete if security events disappear too quickly.
Review:
Retention
Rotation
Disk Capacity
Central ForwardingLog Architecture
Section titled “Log Architecture”Linux Server ↓Local Logs ↓Central Collector ↓SIEM ↓SOCPart 31 — Review Audit Capabilities
Section titled “Part 31 — Review Audit Capabilities”Some Linux environments use:
auditdfor detailed auditing.
Determine whether it is present:
systemctl status auditdwhere applicable.
Security Value
Section titled “Security Value”Audit mechanisms can help record:
Administrative Actions
Sensitive File Access
System Calls
Account Changes
Security EventsStep 33 — Review Existing Audit Rules
Section titled “Step 33 — Review Existing Audit Rules”Where authorized and supported:
sudo auditctl -lDo not add large numbers of audit rules blindly.
Poorly designed auditing can:
Generate Noise
Consume Storage
Reduce Analyst EffectivenessPart 32 — Review Scheduled Tasks
Section titled “Part 32 — Review Scheduled Tasks”Persistence and maintenance can both use scheduled execution.
Review your user crontab:
crontab -lReview relevant authorized system scheduling locations.
Ask:
Who Runs It?
What Executes?
Who Owns the Script?
Can an Untrusted User Modify It?
Is It Required?Part 33 — Review systemd Timers
Section titled “Part 33 — Review systemd Timers”Modern systems may use:
systemd timersReview:
systemctl list-timers --allThis helps identify scheduled system activities.
Part 34 — Review Temporary Files
Section titled “Part 34 — Review Temporary Files”Temporary directories may be used by many applications.
Security concerns include:
Predictable File Names
Weak Permissions
Untrusted Shared Locations
Sensitive Data ExposureDo not delete temporary files blindly.
Applications may actively depend on them.
Part 35 — Review Mount Security
Section titled “Part 35 — Review Mount Security”Run:
findmntReview mount options.
Security-sensitive mount options can include concepts such as:
nosuid
nodev
noexecbut these should not be applied blindly.
Example
Section titled “Example”A filesystem holding executable applications may legitimately require execution.
Therefore use:
Filesystem Purpose ↓Security Requirement ↓Compatible Mount OptionsPart 36 — Review /etc/fstab
Section titled “Part 36 — Review /etc/fstab”Inspect:
cat /etc/fstabDo not modify it without understanding boot impact.
Incorrect entries can prevent normal boot or mount required application storage incorrectly.
Part 37 — Review Kernel Parameters
Section titled “Part 37 — Review Kernel Parameters”Linux exposes runtime kernel settings through mechanisms such as:
sysctlReview selected settings with:
sysctl -a 2>/dev/null | lessDo not change kernel parameters randomly.
Security Areas May Include
Section titled “Security Areas May Include”Networking Behavior
Address Forwarding
Redirect Handling
Memory Protections
Core DumpsThe correct hardening value depends on:
Server Role
Network Architecture
Application Requirement
Approved Security BaselinePart 38 — Baseline Against a Standard
Section titled “Part 38 — Baseline Against a Standard”Enterprise hardening commonly uses recognized guidance such as:
CIS Benchmarks
Vendor Security Guidance
Internal Security BaselinesDo not treat benchmarks as:
Blind Configuration ScriptsUse:
Control ↓Applicability ↓Risk ↓Business Impact ↓Implementation ↓ValidationPart 39 — Review Backups
Section titled “Part 39 — Review Backups”Hardening also protects availability.
Ask:
Is the Server Backed Up?
What Is Backed Up?
Are Backups Protected?
Are They Encrypted?
Can They Be Restored?Critical Principle
Section titled “Critical Principle”Backup Existsdoes not equal:
Recovery Worksuntil restoration has been tested.
Part 40 — Review Recovery Access
Section titled “Part 40 — Review Recovery Access”A hardened system still needs a secure recovery procedure.
Document:
Console Access
Emergency Administrative Access
Recovery Credentials
Break-Glass Procedure
Backup Restore ProcedureThese should be controlled and audited.
Part 41 — Perform Before-and-After Port Review
Section titled “Part 41 — Perform Before-and-After Port Review”Before changes, save:
sudo ss -lntup > baseline/listening-ports.txtAfter approved hardening, save:
sudo ss -lntup > evidence/listening-ports-after.txtCompare:
diff baseline/listening-ports.txt evidence/listening-ports-after.txtWhat You Want
Section titled “What You Want”Not necessarily:
Zero Portsbut:
Only Required PortsPart 42 — Service Comparison
Section titled “Part 42 — Service Comparison”Capture enabled/running service baselines before and after approved modifications.
The goal is to demonstrate:
Reduced Unnecessary Services
No Broken Required ServicesPart 43 — Validate SSH After Hardening
Section titled “Part 43 — Validate SSH After Hardening”After any SSH change:
01 Validate Configuration
02 Reload Safely
03 Keep Existing Session
04 Open Second Session
05 Verify Authentication
06 Verify sudo
07 Confirm LogsNever treat:
Service Reload Successfulas proof that administrators can still log in.
Part 44 — Validate Firewall
Section titled “Part 44 — Validate Firewall”Test:
Required Administrative Access
Required Application Ports
Unexpected Ports
Local ServicesThe security objective is:
Business Function Works +Unnecessary Exposure ReducedPart 45 — Validate Application Health
Section titled “Part 45 — Validate Application Health”Hardening is not complete until business functionality is tested.
Check:
Application Running?
Required Service Healthy?
Required Port Available?
Storage Accessible?
DNS Working?
Authentication Working?
Logs Healthy?Part 46 — Review Reboot Requirements
Section titled “Part 46 — Review Reboot Requirements”Some changes may require:
Service Reload
Service Restart
Application Restart
System RebootDo not reboot automatically without understanding business impact.
Part 47 — Validate Persistence
Section titled “Part 47 — Validate Persistence”A common mistake is creating a secure state that disappears after reboot.
Validate that appropriate settings are persistent.
Examples:
Firewall
Services
Mounts
System Configuration
Security PolicyPart 48 — Hardening Checklist
Section titled “Part 48 — Hardening Checklist”Review the server using:
IDENTITYWho can log in?
PRIVILEGEWho can become administrator?
AUTHENTICATIONHow is access verified?
SSHWho can remotely connect?
FILESWho can read or modify data?
SOFTWAREWhat is installed?
SERVICESWhat is running?
NETWORKWhat is exposed?
FIREWALLWhat is allowed?
MACIs SELinux/AppArmor active?
PATCHINGIs software maintained?
LOGGINGCan events be reconstructed?
AUDITINGAre important actions recorded?
TIMEAre timestamps reliable?
BACKUPCan data be recovered?Part 49 — Hardening Finding 01
Section titled “Part 49 — Hardening Finding 01”Unnecessary Network Exposure
Section titled “Unnecessary Network Exposure”Finding:Unnecessary Network Exposure
Observation:A network service is listening on aninterface accessible beyond itsdocumented business requirement.
Risk:Additional network exposure increasesthe remotely reachable attack surface.
Recommendation:Restrict the service to the requiredinterface or network and enforce accessthrough approved host/network firewallcontrols.Part 50 — Hardening Finding 02
Section titled “Part 50 — Hardening Finding 02”Excessive Administrative Access
Section titled “Excessive Administrative Access”Finding:Excessive Administrative Access
Observation:Multiple accounts possess broadadministrative permissions withoutdocumented operational requirements.
Risk:Compromise or misuse of any privilegedaccount could result in full systemcontrol.
Recommendation:Apply least privilege, remove unnecessaryadministrative memberships, and performperiodic privileged-access reviews.Part 51 — Hardening Finding 03
Section titled “Part 51 — Hardening Finding 03”Unnecessary Software
Section titled “Unnecessary Software”Finding:Unnecessary Software Installed
Observation:Software packages exist on the serverwithout an identified operationalrequirement.
Risk:Additional packages increase attacksurface and patch-management overhead.
Recommendation:Confirm application dependencies andremove unnecessary software throughthe approved change process.Part 52 — Hardening Finding 04
Section titled “Part 52 — Hardening Finding 04”Weak Logging Coverage
Section titled “Weak Logging Coverage”Finding:Insufficient Security Logging
Observation:Security-relevant events are not retainedor centrally collected for an appropriateinvestigation period.
Risk:Security incidents may be difficult todetect, investigate, or reconstruct.
Recommendation:Implement approved security-eventcollection, retention, timesynchronization, and centralized logging.Part 53 — Hardening Finding 05
Section titled “Part 53 — Hardening Finding 05”Mandatory Access Control Not Enforced
Section titled “Mandatory Access Control Not Enforced”Finding:Mandatory Access Control Not Enforced
Observation:The platform's approved mandatoryaccess-control mechanism is not enforcingsecurity policy.
Risk:Compromised processes may operate withfewer restrictions beyond traditionalLinux permissions.
Recommendation:Determine the operational reason,resolve compatibility issues, and restorethe approved enforcement state.Part 54 — Risk Prioritization
Section titled “Part 54 — Risk Prioritization”Not every issue has the same importance.
Use factors such as:
Exposure
Privilege
Exploitability
Business Criticality
Data Sensitivity
Existing ControlsExample prioritization:
Public Administrative Service ↓Higher Priority
Unused Local Package ↓Potentially Lower PriorityContext matters.
Part 55 — Create the Hardening Report
Section titled “Part 55 — Create the Hardening Report”Your final report should contain:
1. Executive Summary
Section titled “1. Executive Summary”Describe:
System Reviewed
Overall Security State
Highest-Risk Issues
Major Improvements2. Scope
Section titled “2. Scope”Hostname
Distribution
Server Role
Review Date
Authorized Scope3. Baseline
Section titled “3. Baseline”Include:
Accounts
Privileged Users
Services
Ports
Packages
Firewall State
Security Controls4. Hardening Actions
Section titled “4. Hardening Actions”For each approved change document:
Control
Previous State
New State
Reason
Validation5. Findings
Section titled “5. Findings”For each issue:
Finding
Observation
Risk
Evidence
Recommendation
Status6. Exceptions
Section titled “6. Exceptions”Document settings intentionally not changed because of:
Application Requirement
Business Requirement
Compatibility
Accepted Risk7. Validation
Section titled “7. Validation”Confirm:
SSH Access
Application Function
Networking
Firewall
Logging
Security Controls
PersistencePart 56 — Hardening Evidence Table
Section titled “Part 56 — Hardening Evidence Table”| Control | Before | After | Validation |
|---|---|---|---|
| Unnecessary service | Running | Disabled | Service absent |
| SSH root access | Review | Hardened if applicable | Second session tested |
| Firewall | Review | Required access only | Connectivity tested |
| SELinux/AppArmor | Review | Approved state | Policy validated |
| Logging | Review | Improved if needed | Events visible |
Part 57 — Security Exceptions
Section titled “Part 57 — Security Exceptions”A professional hardening assessment may produce:
Exceptionrather than:
FailureExample:
Control:Disable Service X
Decision:Not Applied
Reason:Service X is required by the application.
Compensating Controls:Restricted firewall exposureand centralized monitoring.
Owner:Application TeamImportant Lesson
Section titled “Important Lesson”Security engineering is not:
Checklist Says Disable ↓DisableIt is:
Understand Risk ↓Understand Business ↓Design Appropriate ControlPart 58 — Security Baseline Maturity
Section titled “Part 58 — Security Baseline Maturity”Think of hardening as stages.
Level 1 — Basic
Section titled “Level 1 — Basic”Patch System
Remove Unused Accounts
Secure SSH
Enable FirewallLevel 2 — Managed
Section titled “Level 2 — Managed”Approved Baseline
Central Logging
Privilege Review
Automated Updates Process
Configuration MonitoringLevel 3 — Enterprise
Section titled “Level 3 — Enterprise”Configuration as Code
Continuous Compliance
Central IAM
Secrets Management
EDR
SIEM
Automated Drift DetectionPart 59 — Linux Hardening in Cloud
Section titled “Part 59 — Linux Hardening in Cloud”When Linux runs in AWS, Azure, or Google Cloud, host hardening is only one layer.
Think:
Cloud IAM ↓Cloud Firewall ↓Linux Firewall ↓Linux Services ↓ApplicationAll layers matter.
Cloud Security Example
Section titled “Cloud Security Example”Even if:
Linux FirewallIs Correcta weak cloud IAM configuration can still create risk.
Similarly:
Cloud Security GroupIs Restricteddoes not justify poor Linux permissions.
Part 60 — Linux Hardening and Containers
Section titled “Part 60 — Linux Hardening and Containers”Container hosts also require Linux hardening.
Consider:
Host OS
Container Runtime
Users
Services
Firewall
Kernel
SELinux/AppArmor
LoggingA compromised host may affect multiple containers.
Part 61 — Linux Hardening and Kubernetes
Section titled “Part 61 — Linux Hardening and Kubernetes”Kubernetes nodes still rely on Linux security.
Kubernetes ↓Container Runtime ↓LinuxTherefore Linux hardening supports:
Kubernetes Node Security
Runtime Security
Cluster ResiliencePart 62 — Linux Hardening and SOC
Section titled “Part 62 — Linux Hardening and SOC”Hardening creates:
Known Good Baselinewhich improves detection.
For example:
Expected Services = 8Later:
Service 9 AppearsThis creates a meaningful investigation lead.
Part 63 — Linux Hardening and Incident Response
Section titled “Part 63 — Linux Hardening and Incident Response”Strong hardening improves incident response through:
Better Logs
Known Accounts
Reduced Services
Documented Configuration
Accurate Time
Strong Access ControlsWithout a baseline it can be difficult to determine:
Normalversus:
SuspiciousPart 64 — Hardening vs Vulnerability Management
Section titled “Part 64 — Hardening vs Vulnerability Management”These are related but different.
Vulnerability Management ↓Known Software WeaknessesHardening ↓Secure ConfigurationA fully patched server may still be insecure because of:
Weak SSH
Excessive sudo
Open Ports
Bad Permissions
Disabled LoggingPart 65 — Hardening vs Monitoring
Section titled “Part 65 — Hardening vs Monitoring”Hardening reduces opportunities.
Monitoring detects activity.
Hardening +Monitoring +Incident Response ↓Defense in DepthPart 66 — Practical Challenge
Section titled “Part 66 — Practical Challenge”Without immediately applying changes, review your lab server and identify:
3 Identity Controls
3 Network Controls
3 Filesystem Controls
3 Logging Controls
3 Software ControlsFor each classify:
Compliant
Needs Improvement
Not Applicable
Requires Business ReviewPart 67 — Hardening Validation Challenge
Section titled “Part 67 — Hardening Validation Challenge”After approved changes answer:
Can I Still Log In?
Does sudo Still Work?
Is the Application Healthy?
Are Required Ports Reachable?
Are Unnecessary Ports Restricted?
Are Logs Being Generated?
Is Security Policy Active?
Will Settings Survive Reboot?Part 68 — Rollback Plan
Section titled “Part 68 — Rollback Plan”Before every important modification document:
Configuration File:
Backup Location:
Original State:
Recovery Command:
Console Access Available:Yes / NoPart 69 — Common Linux Hardening Mistakes
Section titled “Part 69 — Common Linux Hardening Mistakes”Avoid:
Applying Checklists Blindly
Disabling SELinux
Disabling Firewall to Fix Problems
Removing Unknown Packages
Deleting System Accounts
Using chmod 777
Blocking Your Own SSH Access
Changing sudo Without Validation
Ignoring Application Requirements
Skipping Backups
Skipping Logs
Skipping Reboot ValidationPart 70 — Professional Hardening Workflow
Section titled “Part 70 — Professional Hardening Workflow”Use this in real environments:
01 Obtain Authorization
02 Identify Server Role
03 Gather Baseline
04 Identify Required Services
05 Review Security Standard
06 Identify Gaps
07 Assess Business Impact
08 Create Change Plan
09 Create Rollback Plan
10 Test
11 Implement
12 Validate
13 Monitor
14 Document Exceptions
15 Produce ReportLab Deliverables
Section titled “Lab Deliverables”Submit:
01 System Baseline
02 User and Group Review
03 sudo Review
04 SSH Review
05 Service Inventory
06 Port Inventory
07 Firewall Review
08 Package Review
09 Permission Review
10 SUID/SGID Review
11 SELinux/AppArmor Review
12 Logging Review
13 Audit Review
14 Hardening Findings
15 Before-and-After Evidence
16 Final Hardening ReportInterview Scenarios
Section titled “Interview Scenarios”Scenario 01
Section titled “Scenario 01”A security benchmark recommends disabling a service, but the application team says it is required. What should you do?
Use:
Validate Requirement
Understand Exposure
Apply Compensating Controls
Document Exception
MonitorDo not disable it blindly.
Scenario 02
Section titled “Scenario 02”You change SSH settings and cannot reconnect. What went wrong?
Possible causes include:
Syntax Error
Authentication Disabled
Firewall Rule
User Restriction
Service FailureThis is why you:
Keep Existing Session
Validate Syntax
Test Second Connectionbefore closing access.
Scenario 03
Section titled “Scenario 03”Why should you not disable SELinux simply because an application fails?
Because the failure may represent:
Incorrect Context
Incorrect Configuration
Policy ViolationDisabling SELinux removes an important security layer instead of correcting the root cause.
Scenario 04
Section titled “Scenario 04”Why can a fully patched Linux system still be insecure?
Because security also depends on:
Identity
Privilege
Configuration
Services
Network Exposure
Permissions
LoggingScenario 05
Section titled “Scenario 05”Why capture a baseline before hardening?
Because it helps demonstrate:
Original State
Changes Made
Security Improvement
Rollback Information40 Linux Hardening Interview Questions
Section titled “40 Linux Hardening Interview Questions”- What is Linux hardening?
- Why is system hardening necessary?
- What is attack-surface reduction?
- Why should you establish a baseline before making changes?
- How do you identify interactive Linux users?
- Why should UID 0 accounts be reviewed?
- What is least privilege?
- How would you review sudo access?
- Why are service accounts different from human accounts?
- Why might a service account use
nologin? - What security risks exist with SSH?
- Why is direct root SSH login commonly restricted?
- Why should SSH configuration be syntax-validated?
- Why should you keep an existing SSH session during hardening?
- What is the purpose of a host firewall?
- How do you identify listening ports?
- Why should unnecessary services be disabled?
- Why should unnecessary packages be removed?
- What is a world-writable file?
- Why are world-writable directories security-sensitive?
- What is the sticky bit?
- What is SUID?
- Why should SUID files be reviewed?
- What is SGID?
- Why is PATH security-relevant?
- Why is patch management important?
- Why are third-party repositories a security concern?
- What is SELinux?
- What is the difference between enforcing and permissive?
- Why should SELinux not simply be disabled?
- What is AppArmor?
- Why is time synchronization security-relevant?
- Why is centralized logging useful?
- What does auditd provide?
- Why should scheduled tasks be reviewed?
- What are secure mount options?
- Why should hardening controls be tested for application compatibility?
- What is a security exception?
- What is configuration drift?
- How would you validate a Linux server after hardening?
Linux Hardening Readiness Checklist
Section titled “Linux Hardening Readiness Checklist”Baseline
Section titled “Baseline”- Identified OS
- Identified kernel
- Recorded hostname
- Recorded current identity
- Captured package inventory
- Captured service inventory
- Captured port inventory
Identity
Section titled “Identity”- Reviewed users
- Reviewed UID 0 accounts
- Reviewed interactive shells
- Reviewed service accounts
- Reviewed groups
- Reviewed privileged groups
- Reviewed sudo access
Authentication
Section titled “Authentication”- Reviewed account policy
- Reviewed account aging
- Reviewed SSH access
- Reviewed SSH authentication methods
- Reviewed SSH keys
- Protected administrative access
Software
Section titled “Software”- Reviewed installed packages
- Identified unnecessary software
- Reviewed update status
- Reviewed repository trust
Services
Section titled “Services”- Reviewed running services
- Reviewed enabled services
- Mapped services to business requirements
- Disabled only approved unnecessary services
Network
Section titled “Network”- Reviewed interfaces
- Reviewed listening ports
- Reviewed bound addresses
- Reviewed host firewall
- Validated required connectivity
- Reduced unnecessary exposure
Filesystem
Section titled “Filesystem”- Reviewed sensitive file permissions
- Reviewed world-writable files
- Reviewed world-writable directories
- Reviewed
/tmp - Reviewed SUID files
- Reviewed SGID files
- Reviewed home-directory permissions
- Reviewed SSH-directory permissions
Security Controls
Section titled “Security Controls”- Reviewed SELinux/AppArmor
- Reviewed policy state
- Reviewed time synchronization
- Reviewed system logging
- Reviewed authentication logging
- Reviewed auditing
- Reviewed scheduled tasks
Resilience
Section titled “Resilience”- Reviewed backup status
- Reviewed recovery access
- Documented rollback approach
- Validated required services
- Validated persistence
Documentation
Section titled “Documentation”- Recorded before state
- Recorded after state
- Documented changes
- Documented exceptions
- Created findings
- Created final report
Final Hardening Mental Model
Section titled “Final Hardening Mental Model”When hardening Linux, think:
KNOW THE SYSTEM ↓KNOW THE BUSINESS FUNCTION ↓KNOW WHO NEEDS ACCESS ↓REMOVE WHAT IS NOT REQUIRED ↓RESTRICT WHAT REMAINS ↓PATCH WHAT MUST RUN ↓LOG IMPORTANT ACTIVITY ↓VALIDATE BUSINESS FUNCTION ↓MONITOR FOR DRIFTThe goal is not:
Maximum RestrictionThe goal is:
Minimum Necessary Exposure+Maximum Practical Security+Required Business FunctionMission Accomplished
Section titled “Mission Accomplished”You have now worked through a structured Linux hardening workflow covering:
System Baseline
User Security
Privilege Management
SSH Security
Package Security
Service Reduction
Filesystem Security
Network Exposure
Firewall Controls
SELinux/AppArmor
Logging
Auditing
Time Synchronization
Recovery
ValidationYou have moved from:
Linux Administratortoward:
Linux Security AdministratorMost importantly, you learned that professional hardening follows:
BASELINE ↓UNDERSTAND ↓HARDEN ↓VALIDATE ↓DOCUMENT ↓MONITORWhat’s Next?
Section titled “What’s Next?”➡️ Lab 03 — Linux IAM
In the next lab, you will focus specifically on Linux identity and access management.
You will work through:
Users ↓Groups ↓UID/GID ↓Password Controls ↓Account Lifecycle ↓File Ownership ↓Permissions ↓ACLs ↓sudo ↓Service Accounts ↓SSH Keys ↓Privileged Access ReviewYour Linux lab journey continues:
Lab 01 — Linux Administration ↓Lab 02 — Linux Hardening ↓Lab 03 — Linux IAM ↓Lab 04 — Linux Networking ↓Lab 05 — Linux Security ↓Runbook 01 — Linux Incident Investigation ↓Runbook 02 — Linux Security Assessment ↓Runbook 03 — Linux Server Hardening