Linux server hardening is easy to turn into a collection of copied settings: disable this, install that, close a port, and declare the host secure. A better approach begins with the server's purpose, its exposed paths, the data it handles, and the people who must operate it. Hardening should reduce the chance of compromise, limit the damage if one control fails, and leave enough evidence to detect and investigate change.
This checklist is for developers and small teams running a Linux web, application, or database server. It favors controls that can be verified and maintained over impressive-looking configuration. Test changes in a staging environment where possible, keep an out-of-band recovery path before changing remote access, and adapt every recommendation to the distribution, hosting platform, application, and business risk.
1. Define the server's role and acceptable exposure
Write down what the host is supposed to do before trying to secure it. Record the owner, business purpose, operating system and release, applications, data classification, expected users, public DNS names, required inbound ports, outbound dependencies, backup destination, and recovery objective. A server with no agreed role accumulates packages, accounts, firewall exceptions, and forgotten services because nobody can confidently say what is unnecessary.
Build a simple data-flow sketch: internet or private clients, load balancer, server, database, storage, identity provider, monitoring destination, and administrative route. For each connection, identify who initiates it and why. This makes “default deny” practical rather than aspirational and exposes paths—such as unrestricted database access or a management panel on the public internet—that deserve redesign.
2. Keep an inventory and a supported lifecycle
Confirm that the distribution and major applications still receive security updates. Record the kernel, package sources, enabled repositories, installed packages, container images, language runtimes, and manually installed binaries. Unsupported software turns every other hardening control into a compensating measure with an uncertain deadline.
cat /etc/os-release
uname -r
systemctl list-unit-files --state=enabled
ss -lntup
Do not remove packages simply because a generic guide labels them unnecessary. First confirm the service owner, package dependency, and rollback method. The useful result is a small, explainable software footprint—not a minimal package count that makes recovery harder.
3. Patch deliberately and verify the result
Enable a reliable security-update process appropriate to the distribution, but do not confuse package download with completed remediation. Track whether updates installed, whether services need restarting, whether a new kernel requires a reboot, and whether the application still works afterward. Schedule maintenance according to risk rather than waiting for a convenient but undefined future window.
For internet-facing or high-value systems, define an emergency path for actively exploited vulnerabilities. It should identify who reviews advisories, who can approve downtime, how to test, and what temporary mitigation is acceptable. Package automation helps, but ownership and verification close the loop.
4. Make administrative access individual and recoverable
Give administrators individual accounts so actions remain attributable. Use sudo for controlled elevation, review group membership, and remove stale users promptly. Avoid shared root credentials and do not use application service accounts for interactive administration.
For SSH, prefer strong public-key or certificate-based access, restrict allowed users or groups, and disable direct root login after confirming the replacement path works. Password authentication may be disabled when the team has tested key access, recovery keys, and console access. Do not apply remote SSH changes without keeping a second session open and confirming that the hosting provider's console or rescue path is usable.
sshd -T
getent group sudo
last -a | head
Multi-factor authentication, a VPN, a bastion host, or identity-aware access can add protection to administrative paths. Choose a design the team can operate during an outage; an elaborate access layer without tested emergency recovery can become its own availability risk.
5. Review privileges, secrets, and service identities
Run each application under a dedicated unprivileged account. Check file ownership, writable directories, group membership, Linux capabilities, scheduled jobs, and sudoers entries. A web process should not be able to edit system configuration, read unrelated application secrets, or control the database service merely because all components share one account.
Keep secrets out of source repositories, shell history, process arguments, and broadly readable environment files. Use the platform's secret store where available, restrict file permissions, rotate exposed or inherited credentials, and document which service consumes each secret. Rotation must be rehearsed; an unused “rotate” procedure is not a control.
6. Minimize network exposure at more than one layer
Compare listening sockets with the role definition, then restrict traffic using the cloud security list or security group, host firewall, and application binding. These layers are complementary. A private database should normally listen only where required and accept connections only from approved application sources, not from every address because a password exists.
ss -lntup
ip addr show
nft list ruleset
Use the firewall tool supported by the distribution—such as nftables, firewalld, or ufw—and avoid maintaining competing rule systems without a reason. Review IPv4 and IPv6. Test from both an allowed source and a denied source, because a rule file that looks correct is weaker evidence than an observed connection result.
7. Harden services and isolate workloads
Disable services that have no role, bind administrative interfaces to private addresses, and remove default accounts or sample applications. For web services, use supported TLS configuration, appropriate security headers, request-size limits, and rate controls at the correct layer. For databases, restrict network access, use separate application credentials, and grant only required schema privileges.
Use systemd sandboxing, containers, mandatory access control, or separate hosts where the risk justifies it. Controls such as SELinux or AppArmor are valuable when policies are understood and alerts are reviewed; disabling them to silence an application error removes a protection rather than fixing the application. Introduce isolation incrementally and test normal operations, deployments, backups, and recovery.
8. Protect files, mounts, and temporary locations
Review permissions on configuration, keys, backups, web roots, deployment directories, and logs. Identify world-writable files and unexpected setuid or setgid binaries, but investigate before changing them. Some permissions are required by packaged software; blind remediation can break the host while leaving the real exposure untouched.
Where compatible with the workload, mount options such as nodev, nosuid, or noexec can reduce risk on selected data or temporary filesystems. They are not universal switches: package managers, application installers, containers, and build pipelines may need different behavior. Document exceptions and test them after upgrades.
9. Make logs useful and difficult to erase
Collect authentication events, privilege use, service failures, firewall decisions where useful, application security events, and important configuration changes. Synchronize time so events across the server, proxy, database, and identity provider can be correlated. Protect log access and retention according to the sensitivity of the data.
Forward critical logs or alerts off the host. If an attacker or failed disk can erase the only copy, local logging provides weak investigative value. Avoid recording passwords, tokens, full session cookies, or unnecessary personal data. The goal is actionable evidence, not maximum volume.
10. Treat Linux server monitoring as a security control
A hardened baseline decays. Accounts are added, ports open, packages age, certificates approach expiry, disks fill, services fail, and firewall rules change. Practical Linux server monitoring should track both health and security-relevant drift: failed logins, unexpected listeners, enabled services, patch age, reboot requirements, storage and inode use, certificate dates, failed units, backup results, and changes to critical configuration.
Alert only on conditions that have an owner and a response. A weekly review can be more useful than hundreds of unowned notifications for a small estate, while urgent signals—such as repeated authentication attacks, a failed backup, filesystem errors, or a newly exposed administrative port—need faster handling. Keep a known-good baseline so a new result can be compared with expected state rather than judged in isolation.
11. Back up data, configuration, and recovery knowledge
Backups should include the data and configuration required to rebuild the service, not merely a disk snapshot with unknown consistency. Encrypt backups, restrict deletion rights, separate backup credentials from normal server credentials, define retention, and keep at least one copy outside the server's failure domain. An attacker who controls the host should not automatically gain the ability to destroy every recovery copy.
Test restores on a schedule. Verify database consistency, application startup, secrets recovery, DNS or certificate dependencies, and the time needed to return service. Record the result and the gap between the recovery objective and the observed restore. A successful backup job proves that data was written; only a restore test provides evidence that it can be used.
12. Add integrity checks without creating noise
File integrity monitoring can identify unexpected changes to important binaries and configuration, but it needs a clean baseline and a process for expected updates. Package verification, configuration management drift reports, and version-controlled infrastructure files can provide similar evidence. Focus on critical paths rather than generating an unreviewable list after every patch cycle.
Also inventory scheduled execution: system and user cron jobs, systemd timers, startup units, container schedules, and cloud automation. Persistence often hides in mechanisms administrators rarely review. Every scheduled task should have an owner, purpose, expected output, and failure path.
13. Scan carefully and prioritize findings by exposure
Use vulnerability scanners, configuration benchmarks, and external port scans as evidence sources, not automatic truth. Confirm the installed version, vendor backports, reachable attack path, required privileges, and compensating controls before declaring a finding exploitable. Prioritize internet exposure, active exploitation, sensitive data, privilege impact, and ease of remediation.
Benchmarks such as CIS guidance can help structure a review, but the correct profile depends on the server role. Record accepted exceptions with an owner and review date. A smaller set of remediated high-risk findings is more valuable than a perfect compliance score created by disabling necessary functionality or suppressing results.
14. Prepare for containment and rebuild
Write a short incident runbook before it is needed. Include contact details, evidence-preservation steps, isolation options, credential-rotation order, backup location, rebuild source, DNS and certificate procedures, communication responsibilities, and escalation thresholds. Decide when the safe response is to rebuild from a trusted image rather than attempt an in-place cleanup.
Practice a tabletop scenario: a privileged key is exposed, an unexpected listener appears, or the web server begins contacting an unfamiliar destination. Confirm who can isolate the host without deleting evidence, revoke credentials, restore service, and notify affected parties. Hardening reduces risk; rehearsed response limits the cost when prevention fails.
A maintainable monthly review
For a small team, a maintainable review can be concise: confirm owners and supported versions; review administrators and keys; compare listening ports and enabled services with the baseline; check patch status and required reboots; review failed logins and privilege events; verify certificate, disk, and backup status; inspect firewall changes; and record one tested restore result. Assign each exception to a person and a due date.
The controls should form a loop: define expected state, reduce unnecessary access, monitor for drift, investigate changes, test recovery, and update the baseline. That loop catches the omissions that static hardening lists miss. Security becomes part of operating the server rather than a configuration exercise performed once and forgotten.
Want weekly infrastructure checks without dashboard fatigue?
DMCloud Architect turns Linux and MySQL health signals into practical weekly reports, helping developers and small businesses spot configuration drift, capacity risks, and failed services before they become larger incidents.
Get the free starter plan for weekly infrastructure health reports.