Where do I put files that I want to get deleted on logout?

I was watching a blueray movie that came from a compressed archive, so when I run it directly from ark it gets placed in /tmp.
I got an idea about a thing and to find out if it worked I had to logout/in again so I closed the movie and did just that.
When coming back I thought to myself, “oh ■■■■” I now have to unpack this HUGE file again, but mark my surprise when the file was still there after my logout/in.

So I did a test to confirm it was not just a fluke.
dd bs=1024 count=1048576 if=/dev/urandom of=/tmp/file.tmp status=progress
Logged out, switched tty, logged in and:

$ ls -l /tmp
-rw-r--r-- 1 bedna bedna 1073741824 Dec 29 15:10 file.tmp
drwx------ 2 bedna bedna         40 Dec 29 12:40 plasma-csd-generator.FJWDtd
drwx------ 2 bedna bedna         40 Dec 29 15:00 plasma-csd-generator.lTnzxB
srwx------ 1 sddm  sddm           0 Dec 29 15:11 sddm-:0-KLLyMQ
srwxr-xr-x 1 root  root           0 Dec 29 12:40 sddm-auth-c1e8cca7-33df-4bf9-a5aa-66dd511fb9a7
drwx------ 2 root  root          40 Dec 29 12:40 snap-private-tmp
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-bluetooth.service-938igF
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-ModemManager.service-XYGc29
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-polkit.service-02teRc
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-portmaster.service-s7x51r
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-systemd-logind.service-R2t1ml
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-systemd-timesyncd.service-Y6mOvJ
drwx------ 3 root  root          60 Dec 29 12:40 systemd-private-75ee6b86d5a942d8b4fe56031eb846db-upower.service-BeRKhd
-rw------- 1 sddm  sddm         102 Dec 29 15:11 xauth_irfxav

So should not /tmp get emptied on logout?

$ ls -l -d /tmp
drwxrwxrwt 18 root root 660 Dec 29 15:13 /tmp

EVERYTONE has access to it. (although the files not made by me is (except sddm-auth-c1e8cca7-33df-4bf9-a5aa-66dd511fb9a7 that is a symlink), but still?)

If you, like me, have /tmp mounted as a temporary filesystem (tmpfs), it will go away on reboot

> mount | grep "/tmp"
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,size=7889128k,nr_inodes=1048576,inode64)

Remember, /tmp is not tied to your user, it is a system folder, so it doesn’t make sense that it contents get emptied depending on your user’s login.

1 Like

Arch moved where the umask is defined to /etc/login.defs, I remember there was a pacnew file and apparently I did not pay attention:

# Default initial "umask" value used by login(1) on non-PAM enabled systems.
# Default "umask" value for pam_umask(8) on PAM enabled systems.
# UMASK is also used by useradd(8) and newusers(8) to set the mode for new
# home directories if HOME_MODE is not set.
# 022 is the default value, but 027, or even 077, could be considered
# for increased privacy. There is no One True Answer here: each sysadmin
# must make up their mind.
UMASK           022

Changing UMASK to 027 and I am good with it. :slight_smile:

But still thought the /tmp dir would be emptied from files when logging out. TIL otherwise.

/tmp is emptied on reboot and if memory serves, systemd-tmpfiles-clean.service cleans out files that haven’t been accessed in 24hrs.

Everyone should have access to it, if you need more restrictions then use /run.

1 Like

My whole questioning was flawed because I got confused and thought it was the /tmp dir that made everybody able to read when in fact ALL my files had 644 on them, my old UMASK was overtaken by login.defs I just had not noticed for some reason.

It was all on me.

But I will look into using /run for those temporary file cases instead of /tmp.
Thanks for the tip. :slight_smile:
Might /run/user/1000 be a good place if I want it emptied on logout?

I changed the title to a more fitting question and unlocked the thread again.

I don’t know much about /run, but I think it will be emptied when the user logs out of their last session (ie not if they’re still logged in on tty etc).

Another option could be to create a service to remove the files in a particular dir, then you could put them anywhere.