PrivateTmp= is a systemd service setting that looks like a small hardening flag. It gives the unit a new filesystem namespace and makes /tmp and /var/tmp unavailable to unrelated processes. That can block a whole class of shared-temporary-file attacks. It can also break a service that uses a Unix socket, a named lock, or an upload handoff through those directories.
The systemd manual describes PrivateTmp=true as a per-unit filesystem namespace in which temporary files are removed when the service stops. The same manual notes that PrivateTmp prevents sharing through /tmp or /var/tmp. It changes how the service sees temporary storage beyond the effect of a permission bit.
What it protects
A private temporary namespace reduces the chance that another local process can predict, replace, or read a service's temporary files by path. It also removes the usual host-wide rendezvous directory for cooperative processes. That is useful for a self-contained daemon that creates and consumes its own temporary data within one unit.
The setting does not sandbox the whole service. The process can still access paths allowed by the rest of the unit's settings, its user and group, and the host filesystem. It also does not make secrets in memory safe from a process with sufficient debug rights. Use it with filesystem, capability, and network restrictions rather than instead of them.
Choose the shared state deliberately
If two services must exchange data, do not solve every case by turning off PrivateTmp. A Unix socket that must be shared belongs in a service-owned runtime directory, not an unpredictable temporary path. Application uploads should use an explicit queue or storage path with ownership and cleanup rules. A systemd unit can request a runtime directory that is tied to the service lifecycle and protected by the unit's user and permissions.
The important question is whether the file or socket is personal to the unit or part of an inter-process interface. Temporary pathnames are often treated as both. Namespace hardening exposes that ambiguity during the first deployment, which is useful if the migration is planned rather than patched under incident pressure.
Test the lifecycle
Deploy the setting to a canary unit and test more than startup. Exercise the temporary-file write, every socket path, upload completion, cleanup, restart, and crash recovery. Check whether a second process can see the path and whether the service recreates files with the expected ownership. Look for stale socket errors after a restart and for logs that mention a fallback to a different directory.
Inspect the unit's effective settings with systemctl show <unit> and review the service's journal during a controlled restart. Confirm the result from inside the unit's namespace and from a neighboring process. A PrivateTmp=true line in a drop-in is not evidence that the unit loaded it or that the application honored the environment.
Limits and migration
The namespace is a boundary around filesystem views, not a complete security model. A privileged process can change its namespace or access host resources through an allowed mount. A service running with broad write access can still damage the host. A tool that silently falls back to the current directory may continue working while losing the intended isolation.
For legacy services, map every use of /tmp and /var/tmp before enabling the setting. Where sharing is legitimate, provide a narrow directory with a documented owner and remove broad temporary-directory writes. The migration should leave fewer global rendezvous points, not simply replace one with a permanently world-writable path.