What is the meaning and impact of /run/user/0 and /run/user/1000 directories in Linux(Fedora) ?

Have you ever worked in latest versions of fedora ?

If yes, you might have observed some directories “/run/user/some-number” when doing “df -h”.  Lets see the command output.

[saket@localhost ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   18G  4.4G   12G  27% /
devtmpfs                 492M     0  492M   0% /dev
tmpfs                    502M   80K  502M   1% /dev/shm
tmpfs                    502M  904K  501M   1% /run
tmpfs                    502M     0  502M   0% /sys/fs/cgroup
tmpfs                    502M   16K  502M   1% /tmp
/dev/sda1                477M   95M  353M  22% /boot
tmpfs                    101M   12K  101M   1% /run/user/42
tmpfs                    101M     0  101M   0% /run/user/1000

 

Understanding /run/user directories
1. Identifying users who own these directories.
In the above output, we can see two directories /run/user/42 and /run/user/1000.
Lets try to understand which users are these.

[saket@localhost ~]$ id -a 42
uid=42(gdm) gid=42(gdm) groups=42(gdm)
[saket@localhost ~]$ id -a 1000
uid=1000(saket) gid=1000(saket) groups=1000(saket),10(wheel)
[saket@localhost ~]$ 

[saket@localhost ~]$ ls -l /run/user/
total 0
drwx------.  3 saket saket  60 Sep 21 20:23 1000
drwx------. 11 gdm     gdm     220 Sep 21 20:23 42
[saket@localhost ~]$ 

Hence as we can see in above output, one directory is owned by user saket having UID 1000, and another one is system user gdm with UID 42.

 

2. Explanation
This new concept is deployed by systemd daemon. pam_systemd daemon creates /run/user/$uid directory for every logged in user which is used for storing running processes’ files for that user. It includes various things such as your keyring daemon, pulseaudio, etc.

Earlier these running processes’ files were stored in /tmp and now with systemd its simplified and now stored in /run/user/$uid directory.

/home/$uid can not be sued as it is sometimes mounted on network locations and hence /tmp is the only location other than home directory where all users and read and write.

However storing files in /tmp can be problematic as /tmp can be modified by anyone.

Hence systemd came up with a new directory structure /run/user/$uid.

This directory is local to each system and can be only accessed by the target user. It means applications dont have to worry about access control now.

It even helped to keep things in an organized fashion. On user logout, when no active session exist, pam_systemd will clean /run/user/$uid directory which was very difficult to achieve when using /tmp as files are scattered in same directory.

Leave a Reply

avatar
  Subscribe  
Notify of