Prevent a directory in /tmp from being deleted
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -