{"canonical_url":"https://engineer.company/glossary/hardening/","content_markdown":"# Hardening\n\n## What it is\n\nHardening is the work of configuring a system so that it exposes and permits only what its job\nneeds: fewer running services, fewer listening ports, fewer privileges for each process, and\nstricter defaults on everything that stays. The software is the same before and after. What\nchanges is how much of it an intruder can reach and how far a single foothold carries. You will\nalso see it called system hardening, server hardening, OS hardening or SSH hardening, depending\non which layer is being tightened.\n\nA typical hardening pass on a Linux server touches several layers at once. Remote login accepts\nkeys and refuses passwords. The root account cannot log in directly. Packages nobody uses are\nremoved rather than merely stopped. Each long-running service gets its own unprivileged user, a\nread-only view of the file system, and a list of the system calls it may make. The firewall\nadmits the handful of ports the host exists to serve. None of these steps is exotic; the\ndiscipline is in doing all of them, on every host, and keeping them true.\n\nIt helps to place hardening next to the practices it is often confused with. Patching fixes a\nspecific flaw in code once a fix exists. Monitoring and intrusion detection notice an attack in\nprogress. A firewall decides who may reach a port. Hardening decides what the program behind that\nport is allowed to do once it is reached, and whether the port should be open at all. Published\nbaselines such as the CIS Benchmarks turn this into checklists per operating system and product,\nwhich is useful as a floor and misleading as a finish line.\n\n## Why it matters\n\nThe real decision is where to spend a limited security budget, and hardening is unusual in that\nit pays off against vulnerabilities that will only be found next year. A patch protects against\none known vulnerability. A hardened service restricts what an exploited process can do. For example, denying writes to\nexecutable memory, raw sockets and access to home directories is designed to limit the impact\nof a remote code execution bug. Patching closes holes;\nhardening lowers what any hole is worth. A serious operation needs both, and hardening is what\nbuys time in the days between a disclosure and the fix landing.\n\nThe cost is mostly engineering time and breakage risk rather than licences. Every restriction is\na bet that the service never needs the thing being taken away, and some of those bets lose: a\nbackup job that runs once a night, a log rotation that sends a signal, a plugin that shells out.\nThat is why hardening done by hand on a live server tends to stall. The person doing it gets\nburned once by a restriction that broke something at three in the morning and stops tightening.\nDone as code, with the restrictions reviewed, versioned and applied identically on every rebuild,\nthe same work becomes cheap to repeat and safe to roll back.\n\nFor a buyer, the practical questions are when to do it and how to know it was done. The answer\nto the first is at build time, as part of the automation that creates the host, because a\nchecklist applied once to a running machine drifts within months. The answer to the second\nis evidence from the running system rather than from the configuration repository. Auditors\nincreasingly ask for both: a documented baseline and proof that production matches it.\n\n## What it looks like in practice\n\nOn this company's own production host, SSH is the only interactive way in, and its\nconfiguration is written by automation. In September 2026 an access report read the daemon's\nresolved settings back and found two of the intended directives overridden: the operating\nsystem's defaults loaded ahead of the company's drop-in file, and for those settings the first\nvalue wins. A filename prefix that sorts earlier fixed the order. The lasting change was\n[three-stage validation of 24 SSH directives on every converge](/portfolio/hardened-ssh-to-24-validated-directives/):\neach candidate must parse before it replaces the live file, the configuration as assembled must\npass a check once installed, and then the settings the daemon actually resolved are read back and\nasserted against all 24.\nTwo further directives were left out on purpose because the daemon no longer implements them.\n\nThe same host runs 13 unit files installed by its own automation, and they had been running with\nthe service manager's default privileges. Each unit template received a privilege ceiling, a\nsystem-call filter, restricted address families and memory that may be writable or executable\nbut never both. Measured with the supervisor's own scoring,\n[the sandbox work moved a dead-man's-switch service from 9.6 to 1.5](/portfolio/cut-systemd-sandbox-exposure-on-every-unit/),\nthe internet-facing git forge from 8.3 to 1.5, and the two backup units from 9.6 to 2.3 and 2.5.\nWhile writing them, one directive turned out to be misspelled in three templates; the supervisor\nlogs an unrecognised key and starts the unit regardless. Every unit now passes through the\nsupervisor's own verifier during the converge.\n\nA hardening review in August 2026 asked whether the SSH brute-force protections worked, and read\nthe running system to find out.\n[All three protections had been inert since the host was built](/portfolio/three-locks-on-the-door-none-of-them-locked/):\nthe ban jail watched port 22 while the daemon listened on 1986, a firewall rate limit sat below\na broader rule that matched first, and the ban action called a packet-filter binary the package\nsystem only recommends, which was absent. Two rules came out of that review and still govern the\nrepository: a security control gets an assertion, not a comment, and a firewall is verified by\nthe position of its rules, not by their presence.\n\n## Where it goes wrong\n\n**The setting is in the file and the service ignores it.** Many daemons read several files and\nkeep the first or the last value they meet for each key. A hardened directive in a drop-in can\nlose to a vendor default that loads earlier. Ask the program what it will actually do, for SSH\nwith `sshd -T`, and compare that output with the intended values on every run.\n\n**A typo turns a control into a comment.** Service managers and many daemons log an unknown key\nand carry on. The unit starts, the dashboard is green, and the restriction is absent. Run the\nparser's own verifier as part of deployment so that an unrecognised directive stops the rollout.\n\n```sh\n# What the SSH daemon will do once every Include is resolved\nsshd -T | grep -E '^(passwordauthentication|permitrootlogin) '\n# How much a unit's sandbox still exposes, scored 0.0 to 10.0\nsystemd-analyze security --no-pager example.service\n# Unknown directives and other unit-file errors\nsystemd-analyze verify /etc/systemd/system/example.service\n```\n\n**A protection guards the wrong door.** A port moves and the ban rule keeps watching the old one.\nA rate limit is added below a broad allow rule that already matched. The control reports healthy\nbecause it is running, which says nothing about whether it ever fires. Test each control by its\neffect: trip it on purpose from outside, and confirm the packet is dropped.\n\n**The sandbox breaks the service at night.** A system-call filter or a read-only path breaks\nthe rare code path, such as the weekly export or the backup hook, and the failure appears hours\nafter the change, at runtime rather than at parse time. Tighten in stages, exercise every\nscheduled job after each stage, and watch the journal for processes killed by the filter.\n\n**The benchmark score becomes the goal.** A host can pass every line of a generic checklist while\nits one internet-facing application runs as root with write access to its own code. Start from\nwhat is reachable from the network and what each reachable process could touch, then use the\nbenchmark to catch what that review missed.\n\n## Further reading\n\n- [Hardening, in the NIST glossary](https://csrc.nist.gov/glossary/term/hardening) — the\n  definition NIST uses, with the publication it is drawn from.\n- [sshd_config(5)](https://man.openbsd.org/sshd_config) — every SSH server directive, and the\n  rule that the first value obtained for a keyword is the one used.\n- [systemd.exec(5)](https://man7.org/linux/man-pages/man5/systemd.exec.5.html) — the sandboxing\n  directives for services: system-call filters, address families, write-or-execute memory.\n- [systemd-analyze(1)](https://man7.org/linux/man-pages/man1/systemd-analyze.1.html) — the\n  `security` verb's exposure score and the `verify` verb that catches unknown directives.\n- [CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks) — consensus configuration\n  baselines for operating systems, cloud platforms and server software.\n\n\u003chttps://engineer.company/glossary/hardening/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"Hardening for teams that run their own servers: what to switch off and lock down, what it costs, and how to prove each setting is really in force.","formats":{"gemtext":"https://engineer.company/glossary/hardening/index.gmi","gopher":"https://engineer.company/glossary/hardening/gophermap","html":"https://engineer.company/glossary/hardening/","json":"https://engineer.company/glossary/hardening/index.json","markdown":"https://engineer.company/glossary/hardening/index.md","pdf":"https://engineer.company/glossary/hardening/index.pdf"},"kind":"page","language":"en","title":"What is hardening?","url":"https://engineer.company/glossary/hardening/","version":1}