You are not logged in.
Hello everybody,
Setting up borg backup on my desktop today, I encountered a problem: while root is the user in charge of the backup, the borg’s config and cache files were all stored in my main user’s $HOME directory (/home/kero/.config/borg and /home/kero/.cache/borg) and not in root’s $HOME (= /root).
For now, I solved the problem by setting a $BORG_BASE_DIR variable in my root’s .bashrc, but I’d like to understand where stands the original problem (and if there is a problem). I found out that when I’m in a root session, the $XDG_CACHE_HOME and $XDG_CONFIG_HOME variables use the main user $HOMEdirectory (/home/kero/.cache/ and /home/kero/.config).
Now my question is: is that an intended configuration/behaviour ? If it isn’t, what soft/file/process could be the culprit ? And especially, how to solve this ?
Thank you for reading.
Last edited by kero (2025-02-22 13:34:16)
Offline
How exactly do you start you root shell?
[…] the main user $HOMEdirectory (/home/kero/.cache/ and /home/kero/.config).
This here implies there is a "main user", under which you launched a root shell. Depending on how you do so, it may or may not inherit environment variables from the parent environment.
Offline
Thank you for your answer.
How exactly do you start you root shell?
Well, generally speaking, I work in an XFCE environment (as "kero" user); I open an xfce4-terminal; i "su".
So, everything is normal ?
Last edited by kero (2025-02-21 22:23:58)
Offline
$ man su
...
For backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME if the target user is not root). It is recommended to always use the
--login option (instead of its shortcut -) to avoid side effects caused by mixing environments.
I'm not sure about the "instead of its shortcut -" part – it seems that both "su --login" and "su -" result in the same (correct from your point of view) behavior wrt environment variables.
Offline
I'm not sure about the "instead of its shortcut -" part – it seems that both "su --login" and "su -" result in the same (correct from your point of view) behavior wrt environment variables.
I don’t really know what should be considered as "correct". I’m just surprised by the fact that when borg is run (as root) by a systemd service that I set up, it uses /root/.cache and /root/.config, while it doesn’t when it is run from an xfce-terminal.
Anyway. I’m thinking about setting those XDG* variables in root’s .bashrc. Would that be a good approach ?
Last edited by kero (2025-02-22 12:48:02)
Offline
[…] when borg is run (as root) by a systemd service that I set up, it uses /root/.cache and /root/.config, while it doesn’t when it is run from an xfce-terminal.
Systemd system services don't inherit any user environment variables, and because the XDG basedir variables are not set, it uses the default values as documented.
Anyway. I’m thinking about setting those XDG* variables in root’s .bashrc. Would that be a good approach ?
No, that would just cover up the underlying issue, which is that if you just use plain `su`, you get a root shell that inherits your regular user's environment variables.
Either use `su --login` or `su -` as pointed out by stanczew, or `sudo -i` (to achieve the same with sudo). Or launch a full-blown session with machinectl (though probably overkill).
Either way, you need to launch a proper login shell to get a somewhat clean environment.
Offline
Ok, that's crystal clear now.
Thank you @ayekat and @stanczew for your help in understanding this.
Offline