How to Completely Disable the ‘systemd-tmpfiles-clean’ Service in Ubuntu Server

In Ubuntu Server and other modern Linux distributions, systemd-tmpfiles-clean.service (and its associated timer, systemd-tmpfiles-clean.timer) is a systemd component responsible for periodically purging old, unused, or volatile files and directories from the system (most notably cleaning up /tmp/ and /var/tmp/). It executes the systemd-tmpfiles --clean command based on the aging rules defined in /usr/lib/tmpfiles.d/ and /etc/tmpfiles.d/. While essential for preventing disk exhaustion on standard, long-running desktops or general-purpose servers, this automated background deletion process introduces unacceptable unpredictability in strict, highly specialized environments (such as high-frequency trading platforms, forensic capture nodes, or specialized data ingestion servers) where the absolute retention of all temporary data until explicitly purged by a proprietary application is a hard requirement. Permitting the OS to silently delete files underneath a running application can lead to catastrophic data loss or state corruption.

This guide explains how to completely disable the systemd-tmpfiles-clean service in Ubuntu Server, ensuring absolute suppression of automated temporary file purging by the operating system.

Stop and Mask the systemd-tmpfiles-clean Service and Timer

Because this action is triggered periodically by a systemd timer rather than running as a continuous daemon, we must explicitly disable and mask both the service unit and its controlling timer unit to guarantee the init system is physically prevented from executing the cleanup routine.

  1. Log into your Ubuntu Server via SSH using an account with sudo privileges.
  2. Check the current status of the timer:
    sudo systemctl status systemd-tmpfiles-clean.timer
  3. Disable both the timer and the service to remove them from the systemd scheduling targets:
    sudo systemctl disable systemd-tmpfiles-clean.timer
    sudo systemctl disable systemd-tmpfiles-clean.service
  4. For absolute certainty, explicitly mask both units. This symlinks the unit files to /dev/null, creating a hard cryptographic block against them being invoked by systemd under any circumstances:
    sudo systemctl mask systemd-tmpfiles-clean.timer
    sudo systemctl mask systemd-tmpfiles-clean.service

Verify the Service Lockdown

By masking systemd-tmpfiles-clean.timer and systemd-tmpfiles-clean.service, you guarantee that systemd will completely bypass periodic filesystem cleanup operations, leaving the management of /tmp/ and /var/tmp/ entirely to your proprietary applications or manual administrative intervention.

To verify the lockdown is successful, attempt to start the service manually:

sudo systemctl start systemd-tmpfiles-clean.service

Systemd will return a fatal error stating that the unit is masked (e.g., Failed to start systemd-tmpfiles-clean.service: Unit systemd-tmpfiles-clean.service is masked). Additionally, checking sudo systemctl list-timers will confirm the cleanup timer is no longer scheduled. You have successfully neutralized the automated file purging mechanism, hardening your server’s data retention policies and ensuring compliance with strict state-preservation requirements.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.