Configuring a systemd service with PrivateTmp=true leads to the fact that the service uses a private tmp directory. Instead of /tmp such a service will use a directory like that:


While 94ebb0a353a34259b6c794fe503c35f8 is the boot ID (/proc/sys/kernel/random/boot_id), what is the six characters long ID after service-? In which file is it stored?

  • That random string of 6 character looks very much like the suffix that mkdtemp() adds to make a unique temporary name, so I'd assume that's exactly what it is. I'll check the systemd source and post an answer if my suspicion is right.
    – TooTea
    Oct 19, 2020 at 12:13

1 Answer 1


The six random characters at the end of the systemd-private directory name are only there to guarantee that the directory name is unique and doesn't conflict with any existing directories when it is created. As of systemd v245, this is set up in setup_one_tmp_dir() in src/core/namespace.c. That function calls mkdtemp() to create a unique temporary directory, and mkdtemp() generates the random suffix to guarantee uniqueness.

I haven't found a way to extract the current temporary directory path for a given unit directly from systemd, but if you really need it, you can get that information in these two steps:

  • Run systemctl show some.service -p MainPID and extract the PID (or obtain the PID of any one process in the unit in some other way)
  • Search /proc/ThePID/mountinfo for the mount you're interested in (/tmp or /var/tmp) and extract the path from there.

Note that you only need to do this if there's more than one systemd-private directory for a machine-unit combination present. That is in itself a rare occurence, because systemd removes these directories for units that stop running for any reason. Of course, someone could go and create a systemd-private directory to confuse you, so don't just do systemd-private-$bootID-some.service-* when security is a concern.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .