Skip to content
STAGE33R

Guides · Hardening · updated 3 Dec 2026

How to turn on automatic security updates on Ubuntu, Debian and RHEL

Most exploited vulnerabilities have a patch available for weeks. Automatic security updates install those patches daily, without waiting for you. They install only security fixes by default, which keeps the risk of a surprise low.

  1. Ubuntu and Debian: install and enable

    The first command installs the tool; the second turns on the daily run.

    sudo apt-get install -y unattended-upgrades
    sudo dpkg-reconfigure -plow unattended-upgrades
  2. Check the setting and do a dry run

    Both values should be 1, and the dry run shows what would be installed.

    cat /etc/apt/apt.conf.d/20auto-upgrades
    sudo unattended-upgrade --dry-run --debug 2>&1 | tail -n 15
  3. Decide about reboots

    Kernel fixes need a reboot. Leave automatic reboot off on servers where a restart must be planned, and use a monitor to tell you when one is waiting.

    # /etc/apt/apt.conf.d/50unattended-upgrades
    Unattended-Upgrade::Automatic-Reboot "false";
  4. RHEL, Rocky and Alma: dnf-automatic

    Set it to apply security updates only.

    sudo dnf install -y dnf-automatic
    sudo sed -i 's/^upgrade_type.*/upgrade_type = security/; s/^apply_updates.*/apply_updates = yes/' /etc/dnf/automatic.conf
    sudo systemctl enable --now dnf-automatic.timer
  5. Services keep the old code until restarted

    After a library update, running services still use the old version. needrestart lists and restarts them.

    sudo apt-get install -y needrestart
    sudo needrestart -r l   # list; use -r a to restart automatically

Common mistakes

  • Enabling automatic reboot on a server with services that are not set to start at boot.
  • Third-party repositories are not covered by the default security-only origin list.
  • No monitoring: the updates install, but nobody notices when one fails.

How to undo it

Set both values in 20auto-upgrades to 0, or disable the dnf-automatic timer. Installed packages stay installed; downgrade a specific one with apt-get install package=version.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.