Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 37 ยท Packages and Services

Repositories, Signing Keys and Patch Management

Configure package repositories safely, understand GPG signing keys, enable automatic security updates and plan patching, reboots and rollbacks on Linux servers.

A repository is a server that publishes packages and an index describing them. Which repositories you trust decides what code runs as root on your machines, so repository management is a security task as much as a convenience. This lesson covers how repositories are configured, how signatures protect you and how to keep a fleet patched.

Where repository settings live

Debian family:

Terminal
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
ls /etc/apt/keyrings/ /usr/share/keyrings/
apt policy nginx          # which repository offers which version

Newer releases use the deb822 format in *.sources files:

TEXT
Types: deb
URIs: https://deb.example.com/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg

Red Hat family:

Terminal
ls /etc/yum.repos.d/
dnf repolist
dnf repoinfo
TEXT
[example]
name=Example repo
baseurl=https://rpm.example.com/el9/$basearch
enabled=1
gpgcheck=1
gpgkey=https://rpm.example.com/RPM-GPG-KEY-example

Why signatures matter

Packages and repository indexes are signed with GPG keys. Your system stores the public key of each repository and refuses data that does not match. Without that check, anyone who could intercept or alter a download could ship malicious software.

Rules of thumb:

  • Keep gpgcheck=1 on Red Hat systems; never disable it to silence an error.
  • On Debian, scope each key to its repository with Signed-By, instead of trusting it for every repository system-wide (the old apt-key add method is deprecated).
  • Fetch the key over HTTPS from the vendor's documented location and, when offered, verify its fingerprint.
  • Add third-party repositories rarely and only from vendors you would trust with root.

Release channels and components

A distribution splits repositories by purpose. Debian has components main, contrib, non-free; Ubuntu has main, universe, multiverse, restricted; the Red Hat family has BaseOS and AppStream plus optional extras such as EPEL. Security updates usually come from a separate repository (security.debian.org, *-security, or the update stream), so even a "frozen" system keeps getting fixes.

Updating safely

Terminal
sudo apt update && apt list --upgradable
sudo apt upgrade
sudo dnf check-update --security
sudo dnf upgrade --security

A sensible process:

  1. Test first on a staging machine that mirrors production.
  2. Snapshot or back up (a VM snapshot, an LVM snapshot, or a tested file backup).
  3. Update in a window, with someone watching.
  4. Check services after: systemctl --failed, application health checks.
  5. Reboot when the kernel or core libraries changed.

Does it need a reboot?

Terminal
ls /var/run/reboot-required        # Debian family flag file
sudo needrestart                   # which services use old libraries
sudo dnf needs-restarting -r       # Red Hat family

Automatic updates

Terminal
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

sudo dnf install dnf-automatic
sudo systemctl enable --now dnf-automatic.timer

Automatic security updates close known holes quickly; the trade-off is a small chance of a surprise. Restrict automation to security updates, set e-mail or log reporting and decide whether automatic reboots are acceptable (timers drive these jobs).

Mirrors and internal repositories

Large environments run a local mirror or cache (for example apt-cacher-ng, or Pulp and Foreman) so that machines update from inside the network, versions are consistent and a bad upstream release can be held back. Point sources at the mirror instead of the public servers.

flowchart LR
    A["Upstream repo"] --> B["Internal mirror"]
    B --> C["Staging servers"]
    C --> D["Production servers"]

Patches flow through staging before production.

Rolling back

  • dnf history undo <id> reverses a transaction.
  • With apt, install the earlier version explicitly (apt install pkg=old-version) if it is still in the cache or repository, and apt-mark hold it.
  • Snapshots (LVM, VM, Btrfs) give the cleanest rollback (LVM).

A stand-in: patch priority

This model ranks made-up pending updates so security fixes with an affected service come first. It illustrates triage logic.

Python Stand-in: which updates first?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: read a repository file

This model parses a .repo-style block and flags a missing signature check.

Python Stand-in: audit a .repo file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Disabling signature checks to get past a key error.
  • Adding many third-party repositories that replace system libraries.
  • Patching all production servers at once with no staging.
  • Ignoring reboot-required notices for months.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What protects you from tampered packages?

    Packages and indexes are signed; the system verifies them with stored public keys.
  2. 2. What should gpgcheck be in a Red Hat repo file?

    gpgcheck=1 enforces package signature verification.
  3. 3. What is a sound update process order?

    Test and prepare a way back before changing production.
  4. 4. Why use an internal mirror?

    A mirror gives control over what machines receive and when.

Summary

  • Repositories decide what code runs as root, so keep them few and trusted.
  • Keep signature checking on; scope keys with Signed-By on Debian.
  • Patch through staging, with backups and checks, and watch for reboot needs.
  • Automate security updates carefully and know how to roll back.

Next: Managing Services with systemd