Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1183  / 1 Year ago, mon, december 5, 2022, 10:29:54

I am setting up a system (ubuntu 12.04) that uses ldap, pam, and autofs to load users and their home folders from a remote server. One of the options for login is sitting down at the machine and starting a GUI session. Programs such as chormium (browser) that preform many read/write operations in the ~/.cache and ~/.config files are slowing down the GUI experience as well as putting strain of the NFS server that is causing other users to have problems.



Ubuntu had the handy-dandy XDG_CONFIG_HOME and XDG_CACHE_HOME variables that can be set to change the default location of .cache and .config from the home folder to somewhere else. There are several places to set them, but most of them are not optimal.




  1. /etc/environment




    • pros: will work across all shells

    • cons: cannot use variables like $USER so that you can't make users have different new locations for .cache and .config. Every users' new location would be the same directory.


  2. /etc/bash.bashrc




    • pros: $USER works, so you can place them in different folders

    • cons: only gets run for bash compatible shells


  3. ~/.pam_environment




    • pros: works regardless of shell

    • cons: cannot use system variables (like $USER), has it's own syntax, and has to be created for every user



More From » 12.04

 Answers
3

My solution works for all shells and is done automatically so no admin action required for new users. It uses ~/.pam_environment along with a short script to be run on login.



On a users' login, the short script looks in the users' home directory for the .pam_environment file. If it is not present, it creates it and adds the lines to set XDG_CACHE_HOME and XDG_CONFIG_HOME. Note that in my instance, I am putting the .config and .cache files in /home/nfs_users/username/



It is also possible to put them in /tmp/username/ . These will be destroyed every reboot. You may wish to put yours somewhere more permanent.




  1. Enable the use of ~/.pam_environment :




    • in the file "/etc/pam.d/common-session" add the following line to the end of the file:



      session required pam_env.so



  2. Create a shell script to run on user login. It is "/etc/profile.d/local.sh". You may or may not already have something in this file. You may add the following code, or create the file if it does not exist. NOTE: the chosen directory (in this case /home/nfs_users/) must exist and be writable by all users that log in.



    if [ ! -d '/home/nfs_users/'${USER} ]; then
    mkdir '/home/nfs_users/'${USER}
    fi
    if [ ! -e ${HOME}/.pam_environment ]; then
    echo 'XDG_CACHE_HOME DEFAULT="/home/nfs_users/'${USER}'/.cache"' > ${HOME}"/.pam_environment"
    echo 'XDG_CONFIG_HOME DEFAULT="/home/nfs_users/'${USER}'/.config"' >> ${HOME}"/.pam_environment"
    fi

  3. Then make the script executable:



    sudo chmod +x /etc/profile.d/local.sh


  4. Verify that it works. Log out and log back in. echo $XDG_CONFIG_HOME and echo $XDG_CACHE_HOME should return the proper directories. Also, once you start running GUI applications that use the cache, the .config and .cache files should have some things in them (check their contents with ls).




UPDATE:



So the old solution stores the files in temporary memory, so it will reset on logout and shutdown. To avoid this, don't store the files in /tmp



This changes step 2. I chose to create a folder in /home for the nfs_users (/home/nfs_users) which needs to be writable by all the users that can log in. You may choose to put it somewhere else.


[#35175] Tuesday, December 6, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bathtusain

Total Points: 380
Total Questions: 124
Total Answers: 111

Location: Trinidad and Tobago
Member since Sat, Apr 9, 2022
2 Years ago
;