Sub topic 1
Why patch, and what a patch routine must balance
Prerequisites
This chapter assumes you can do the following:
- Use a Linux shell and
sudocomfortably. - Explain what a package and a package repository are. A package is a bundle of files plus metadata. A repository is a server that hosts packages and an index of them.
- Read the output of
systemctl statusfor a service or a timer. - Log in over SSH to a Debian/Ubuntu or RHEL-family test machine. Use a machine you are allowed to break.
This chapter has no commands that change the system. It sets up the reasoning the later chapters rely on. You will learn what a patch routine is for, what it risks, and how to judge those risks.
Why servers need patching
A server runs software written by people who make mistakes. Some of those mistakes are security flaws. When a flaw is found and fixed, the fix is published as an updated package. Your server stays vulnerable until you install that update.
The gap between a fix being published and a fix being installed is your exposure window. Attackers watch for new fixes. Once a fix is public, they can compare old and new code to learn what was wrong. For a widely used component, such as OpenSSL, the sudo package, or the Linux kernel, exploit code can appear within days. A server that is internet-facing and unpatched is an easy target.
Security fixes are not the only reason to patch. Updates also deliver:
- Bug fixes for crashes, data corruption and memory leaks.
- Behavior fixes, such as updated time zone data or certificate authority lists.
- Compatibility changes that keep the system working with the rest of the world.
- New hardware support, mostly in the kernel.
Skipping updates feels safe because nothing changes. In practice it builds up risk. Each month without patches adds more known flaws. Large, infrequent catch-up updates also change more at once, so they are more likely to break something and harder to diagnose when they do.
What a patch routine must balance
Patching is a trade-off between two kinds of risk.
- The risk of not patching. A known flaw stays open to attack.
- The risk of patching. An update may change behavior, fail to install, restart a service at a bad time, or need a reboot.
A good routine does not eliminate either risk. It keeps both small and makes them predictable. The table lists the main forces you balance.
| Force | Pulls toward | Cost of going too far |
|---|---|---|
| Security exposure | Patch fast and often | Less time to test, more surprise outages |
| Stability | Change as little as possible | Longer exposure window, bigger later jumps |
| Availability | Avoid downtime and restarts | Updated libraries stay unused until restart |
| Effort | Automate everything | Unattended changes nobody reviews |
| Reversibility | Keep a way back | Snapshots and backups cost storage and time |
No setting is correct for every server. A public web server, an internal database and a lab VM deserve different cadences. The rest of this tutorial gives you the tools. This chapter helps you decide how to use them.
The phases of a patch routine
Every routine, however simple, has the same phases. Later chapters cover each one in detail.
- Refresh. Download current package lists from the repositories.
- Review. See what would change before changing anything.
- Test. Apply the updates somewhere safe first.
- Apply. Install the updates on production.
- Restart. Reboot, or restart services, so the new code is the code that runs.
- Verify. Confirm that services work and that the system is healthy.
- Record. Keep a log of what changed and when, so you can roll back or explain it later.
Skipping a phase is where most patching trouble starts. Applying updates without reviewing them hides surprises. Applying without restarting leaves old code running in memory. Applying without verifying means you learn about failures from your users.
Why a restart matters
Installing a package replaces files on disk. It does not always change what is running.
A running process loads its code into memory when it starts. If the package manager replaces a shared library on disk, a process that started earlier keeps using the old copy until it restarts. The flaw you wanted to fix is still present in that process.
The Linux kernel is the strongest example. A new kernel package puts new files in /boot, but the machine keeps running the old kernel until it reboots. Services have the same problem on a smaller scale. A new openssl library does not help a web server that loaded the old one last month.
This is why "I ran the updates" and "the server is patched" are different statements. A patch routine has to include a way to find out what still needs a restart. A later chapter shows the commands for this on both families.
Where the two package families differ
Debian/Ubuntu and RHEL-family systems solve the same problem with different tools and habits. The differences affect how you design a routine.
| Topic | Debian/Ubuntu (`apt`) | RHEL-family (`dnf`) |
|---|---|---|
| Low-level tool | `dpkg` | `rpm` |
| Security updates | Delivered through a separate security archive or pocket | Marked in advisories that `dnf` can filter on |
| Undo support | No undo command, but a log of past runs | Transaction history with `dnf history undo` |
| Automatic updates | `unattended-upgrades` | `dnf-automatic` |
| Reboot hint | `/var/run/reboot-required` file | `dnf needs-restarting -r` |
These are the habits to keep in mind. On Debian and Ubuntu, you plan rollback in advance, because the package manager will not do it for you. On RHEL-family systems, you can lean on the transaction history, but an undo is still not a guarantee. It can fail if the old package versions are no longer in a repository.
Choosing a cadence
How often you patch depends on how exposed the server is and how much change it can tolerate. These are starting points, not rules.
- Security updates on internet-facing servers: within days of release. Many teams aim for about one week. For a severe flaw that is already being exploited, patch sooner and treat it as an emergency.
- Routine updates on internal servers: on a fixed schedule, for example monthly, in a maintenance window.
- Kernel and core library updates: schedule them with a reboot. Plan the downtime or use redundancy so you can reboot one node at a time.
- Release upgrades: treat them as projects, not patches. Moving to a new major distribution release is covered in a later chapter.
A fixed schedule beats an ad hoc one. If patching happens "when someone has time", it tends not to happen. A calendar slot, a named owner and a written checklist turn patching into a routine.
Common mistakes
These errors come up often. Each one is easy to avoid once you know the pattern.
- Patching production first. Without a test run you find breakage on the machine your users depend on.
- Treating "installed" as "running". Pending reboots and restarts stay unnoticed for months.
- Ignoring held packages. A package you pinned once and forgot never gets security fixes. Review holds on every cycle.
- Having no way back. If the only recovery plan is "fix it live", a bad update becomes a long outage. Take a snapshot or backup first on important systems.
- Automating without watching. Automatic updates reduce delay but they still need logs, alerts and an occasional review.
- Patching all servers at once. A bad update then breaks everything together. Roll out in stages instead.
Summary of the routine you will build
By the end of this tutorial you will have a routine that looks like this:
- A scheduled refresh and review of pending updates.
- Security updates applied first and fastest.
- A test machine that receives updates before production.
- Production updated in stages, with a rollback plan.
- A restart decision for each run, based on commands rather than guesswork.
- Logs and a short verification checklist after every run.
- Optional automation for low-risk updates, set conservatively.
Exercise
A teammate says, "I ran the updates last night, so the web server is patched." Name two reasons that statement might still be wrong, and say what you would check.
Show answer
First, the update may have replaced a shared library (such as OpenSSL), but the web server process started before the update and still has the old code in memory, so it needs a restart. Second, the update may have included a new kernel, and the machine keeps running the old kernel until it reboots. Also, a held or version-locked package would not have been upgraded at all. To check, look for a pending reboot (on Debian/Ubuntu, the /var/run/reboot-required file; on RHEL-family systems, the exit code of dnf needs-restarting -r), see which services need a restart, and list held or locked packages.
Exercise
You manage one public web server and one internal file server. Give one reason to patch the web server on a faster cadence than the file server, and one reason not to apply every update to both on the same day.
Show answer
The web server is reachable from the internet, so its exposure window matters more, and attackers can reach any known flaw directly. Applying updates to both servers at the same time, with no test first, means a bad update can break both at once and leave you no working reference system. Updating a test machine or one server first lets you catch problems before they spread.