How to configure Fedora / RedHat / CentOS to delete files in /tmp on boot

Yves Dorfsman asked:

How can you configure Fedora / RedHat / CentOS systems to delete files in /tmp on boot like Debian and Ubuntu?

My answer:

By default /tmp is a tmpfs, and doesn’t exist on boot anyway. To get into this situation, your server must already be non-standard in some way: Someone explicitly configured your system to not have /tmp emptied on boot.

So it is best to fix the problem, by undoing whatever changes were made to cause /tmp to not mount as a tmpfs on boot:

  1. Make sure the mount has not been disabled:

    systemctl unmask tmp.mount

    If this command fails, fix the problem before continuing.

  2. Go to single user mode. You need to be on the console for this.

    systemctl start
  3. Empty the /tmp directory on the hard drive, to clear out the used space.

    rm -rf /tmp
    mkdir -m 1777 /tmp
  4. On CentOS 7, you need to explicitly enable the mount. On Fedora, you can skip this.

    systemctl enable tmp.mount
  5. Restart the system.

    systemctl start

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.