Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Linux Hardening

Direct answer

Linux hardening applies a baseline: minimal packages and services, automatic security updates, strong authentication, SSH hardening, firewall, MAC enforcing, secure mount options, kernel sysctl settings, auditing and logging. Benchmarks such as CIS describe it.

When to use this

Use it to build a secure baseline or check a server against one.

First 30 seconds

1. Scan: oscap xccdf eval --profile <cis> … or lynis audit system.

2. Updates automatic? (unattended-upgrades / dnf-automatic)

3. Unneeded services disabled (systemctl list-unit-files --state=enabled).

4. sysctl hardening (net.ipv4.conf.all.rp_filter, kernel.kptr_restrict…).

5. Re-scan after fixes.

Operational verification

baseline defined → applied by automation → scanned → findings fixed → re-scanned

Evidence · next step

For Security → Linux Hardening, continue with the first unproven Topic check: Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Linux Hardening. If that boundary is healthy, advance to the adjacent check: Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Key commandss -tulpn
Scope / prerequisiteUse it to build a secure baseline or check a server against one.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

host role + threat model → approved baseline → configuration deployment → loaded kernel/service/security state → allow/deny workload tests → audit/drift → remediation/recovery

Healthy evidence: the selected baseline matches host role/version, effective controls are verified, exceptions are documented, drift is monitored and workload/recovery acceptance tests pass

Step 2 Verification and output interpretation Verify boundary

Verification chain. host role + threat model → approved baseline → configuration deployment → loaded kernel/service/security state → allow/deny workload tests → audit/drift → remediation/recovery

Step 3 Commands Verify boundary
lynis audit system
ss -tulpn
systemctl list-unit-files --state=enabled
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: wrong distribution guidance, config is not loaded, permissive controls remain, unnecessary services/privilege persist, patch/reboot gaps exist, audit blind spots remain or recovery is broken

Step 5 Common mistakes Narrow the fault
  • Hardening without a baseline or testing.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Automate the baseline (Ansible, OpenSCAP) rather than hand-editing. Scan with OpenSCAP (oscap) or Lynis and fix findings by priority. Test services after each hardening change.

Key checks
  • sestatus / aa-status — SELinux or AppArmor state
  • ss -tulpn — listening services
  • journalctl -u sshd -g 'Failed' — failed logins
  • ausearch -m avc,user_login -ts today — audit events (auditd)
ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Hardening is resolved only when controls are appropriate to the host role, effective state matches intent, workload and recovery remain functional, and deviations are explicitly accepted or remediated.

In depth

Harden services with systemd sandboxing

Every exposed service benefits from restrictions applied by the service manager. The systemd.exec manual documents options such as ProtectSystem= (read-only system directories), ProtectHome=, NoNewPrivileges=, PrivateTmp= and CapabilityBoundingSet=.

# /etc/systemd/system/myapp.service.d/hardening.conf
[Service]
NoNewPrivileges=yes
ProtectSystem=strict
ReadWritePaths=/var/lib/myapp /var/log/myapp
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
SystemCallFilter=@system-service
$ systemctl daemon-reload && systemctl restart myapp
$ systemd-analyze security myapp.service
  NAME                         DESCRIPTION                              EXPOSURE
✗ PrivateNetwork=              Service has access to the host's network      0.5
✓ ProtectSystem=               Service has strict read-only access to the OS …
→ Overall exposure level for myapp.service: 3.1 OK 🙂

systemd-analyze security scores each unit; start with internet-facing services that score high (UNSAFE/EXPOSED).

Host baseline checklist

AreaCheck
UpdatesAutomatic security updates (unattended-upgrades / dnf-automatic) and reboot policy for kernels
SSHKeys only, no root password login (sshd -T \| grep -E 'permitrootlogin\|passwordauthentication')
Listening servicesss -ltnup — remove what is not needed
FirewallDefault deny inbound (nft list ruleset)
MACSELinux enforcing / AppArmor profiles loaded
AccountsNo unused accounts with shells; sudo via groups, logged
Kernel parameterssysctl kernel.kptr_restrict kernel.dmesg_restrict net.ipv4.conf.all.rp_filter
LoggingPersistent journal or remote log shipping

Roll out safely

Apply sandboxing options one group at a time and watch journalctl -u myapp for Permission denied, Read-only file system or EPERM — then add the specific ReadWritePaths= or capability instead of dropping the protection.

*The sandbox configuration and systemd exposure assessment are illustrative examples, not a completed security audit.*

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Linux Hardening is part of Security → Linux Hardening. Linux Hardening applies role- and distribution-specific secure configuration across boot/kernel, identities, services, SSH/PAM, storage, LSMs, firewall, audit, updates, secrets and recovery while controlling drift.

Topic-specific state model. Linux Hardening applies role- and distribution-specific secure configuration across boot/kernel, identities, services, SSH/PAM, storage, LSMs, firewall, audit, updates, secrets and recovery while controlling drift.

Interpretation rule. - Passing a hardening checklist ≠ effective runtime enforcement or acceptable residual risk.

  • A generic benchmark item ≠ appropriate policy for every Linux role, distribution or workload.

Method

A practical Linux hardening baseline:

1. Minimal install; remove unused packages and services (systemctl list-unit-files --state=enabled).

2. Automatic security updates (dnf-automatic, unattended-upgrades), kernel live patching where needed.

3. SSH: keys only, no root login, restricted users/groups and source networks.

4. Host firewall default deny inbound.

5. SELinux enforcing / AppArmor enforcing.

6. sudo with named accounts and logging; no shared root password use.

7. auditd rules and central logging; time sync.

8. Filesystem options: nodev,nosuid,noexec on /tmp, /var/tmp, /dev/shm where possible.

9. Kernel sysctls: kernel.kptr_restrict=2, net.ipv4.conf.all.rp_filter=1, fs.protected_symlinks=1.

10. Scan with OpenSCAP/Lynis and track deviations.

lynis audit system
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Hardening is resolved only when controls are appropriate to the host role, effective state matches intent, workload and recovery remain functional, and deviations are explicitly accepted or remediated.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Linux Hardening owns platform-wide baseline composition; specialist branches own each control’s detailed implementation and evidence.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Security → Linux Hardening. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.kernel.org/security/index.html · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
linux hardeningserver hardening linuxlinux security baseline
Embedded reference data

Quick lookup tables

Linux Hardening operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Linux Hardening.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateLinux Hardening applies role- and distribution-specific secure configuration across boot/kernel, identities, services, SSH/PAM, storage, LSMs, firewall, audit, updates, secrets and recovery while controlling drift.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host + boot/time + real identity/workload → identify authoritative policy/key/trust source → read back loaded/effective runtime state → reproduce one safe allow/deny/handshake test → correlate audit/service/kernel evidence → locate first failed boundary → make the smallest persistent change → repeat original workload + regression/recovery check.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainhost role + threat model → approved baseline → configuration deployment → loaded kernel/service/security state → allow/deny workload tests → audit/drift → remediation/recoveryTrace requested/configured state through effective state to the observed workload result.
Failure boundaryHardening closes only when controls are appropriate to the host role, effective state matches intent, workload and recovery remain functional, and deviations are explicitly accepted or remediated.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux security/trust evidence can establish this proof path: host role + threat model → approved baseline → configuration deployment → loaded kernel/service/security state → allow/deny workload tests → audit/drift → remediation/recoveryUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove unobserved identities, objects, policies, namespaces, endpoints or time periods. Hardening closes only when controls are appropriate to the host role, effective state matches intent, workload and recovery remain functional, and deviations are explicitly accepted or remediated.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven security/trust boundary, capture the adjacent effective state and audit/handshake evidence, make only the demonstrated persistent change, then repeat the original workload plus recovery/regression checks.Continue to the next unresolved boundary while preserving the original test condition.

Linux Hardening · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryLinux Hardening
Topic pathSecurity → Linux Hardening
Runtime stateLinux Hardening applies role- and distribution-specific secure configuration across boot/kernel, identities, services, SSH/PAM, storage, LSMs, firewall, audit, updates, secrets and recovery while controlling drift.
Fast checks- Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Linux Hardening. - Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. - Reproduce one safe allowed/denied or handshake/access test and correlate kernel/service/audit evidence at the first relevant boundary. - Apply the smallest persistent cause-specific change, then repeat the original test plus an adjacent regression/recovery check.
Verification chainhost role + threat model → approved baseline → configuration deployment → loaded kernel/service/security state → allow/deny workload tests → audit/drift → remediation/recovery Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryHardening closes only when controls are appropriate to the host role, effective state matches intent, workload and recovery remain functional, and deviations are explicitly accepted or remediated. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?