You are not logged in.
I want to add "/usr/sbin" to the PATH so I (or my scripts) can run a few sbin commands without needing sudo (examples: ifconfig, showmount). This is mainly for personal convenience.
In slim + Xfce, I can create a .sh file in /etc/profile.d, and append to the PATH:
PATH=$PATH:/example/path
But this doesn't work with lightdm. My testing shows that lightdm doesn't run /etc/profile, which means none of the scripts in /etc/profile.d are run. And I've confirmed that the problem is lightdm, because when I switched from slim + Xfce to lightdm + Xfce, /etc/profile is NOT run anymore.
* Solutions that don't work for me
- Use ~/.xsessionrc. This doesn't work because TTY (CTRL+ALT+F1), ssh, or telnet does NOT run ~/.xsessionrc.
- Use ~/.bashrc. This doesn't work if I double click on a script file to launch it. ~/.bashrc is NOT run.
- Use /etc/environment. This also doesn't work in TTY, ssh, or telnet. It also requires me to hardcode the rest of the system paths, because /etc/environment does not support script syntax, so I can't append to an existing PATH value.
- Maybe I can find where PATH is first initialized globally, and append my path there. I've tried:
- The initial PATH value is "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games", and I've confirmed that even though /etc/profile sets the PATH to this string, this string is ALREADY set to PATH at the start of /etc/profile. Where is it coming from?
- I searched /etc for "/usr/games", and the only file that could make sense is /etc/login.defs. But when I manually appended a dummy path "/dbg/logindefs", and rebooted, the dummy path is NOT in PATH.
- I extracted the ramdisk /boot/initrd.img-6.12.63+deb13-amd64, and did not find "/usr/games". Now I'm out of ideas.
* Questions
? Where can I append to the PATH globally?
? Also, where exactly is the PATH first initialized?
Last edited by Eeqmcsq (2026-02-01 01:18:02)
Offline
I see in slim.conf: default_path /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
but I'm not seeing anything similar in lightdm.conf.
Evidently, TTY login gets path from /etc/profile, then ~/.profile - both of which seem to be ignored by lightdm
I know it's not answering your questions (I don't know the answers), but for now you could use a combination of /etc/profile (for tty) and ~/.xsessionrc (for X)
(edit)
From this page https://wiki.archlinux.org/title/LightDM
LightDM starts your display and does not source your shell. LightDM launches the display by running a wrapper script and that finally exec's your graphic environment. By default, /etc/lightdm/Xsession is run.
5.3.1 Environment variables
The script checks and sources /etc/profile, ~/.profile, /etc/xprofile and ~/.xprofile, in that order.
I was not able to get xprofile to work, either. I'm wondering if something is missing or misconfigured by default, or if this is a bug.
Last edited by rbit (2026-02-01 03:28:05)
Offline
I think I found that same archlinux page after my initial post, and I also couldn't get /etc/xprofile to work. I had also thought about appending the path in two places to handle all of my cases. So it looks like we've been down the same path of thinking.
* Solution for lightdm
- Create a .sh file in /etc/profile.d, append /usr/sbin to the PATH variable. This covers the tty/telnet/ssh cases.
- Create a local file ~/.xsessionrc, append to the PATH variable. This covers the MATE Terminal and double-click-on-script cases.
A quick test of all of my test cases running "ifconfig" without sudo confirms this solution works for me. I'll marked this as solved.
Offline
Here are my final investigation notes before I clean up and move on. Perhaps someone will find this useful.
* Slim notes
- The reason why using slim triggers /etc/profile to run is because the "login_cmd" defined in /etc/slim.conf explicitly runs bash as a login shell. Bash then runs /etc/profile.
login_cmd exec /bin/bash -login /etc/X11/Xsession %session- /etc/slim.conf does have a "default_path" setting. But if you append a path to this setting, it doesn't appear to work. That's because the bash login runs /etc/profile, which overwrites the current PATH anyway.
You can confirm that the "default_path" does work by adding a dummy path to "default_path":
default_path /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/dbg/slimconfthen printing the PATH variable out to a file at the very top of /etc/profile:
echo "Top of /etc/profile, PATH is $PATH" >> /tmp/dbglog.txtYou'll see in the log file that "/dbg/slimconf" is in the PATH, confirming that slim really is using "default_path".
* Lightdm notes
- I downloaded the lightdm source code, then compiled and debugged it. The source code hardcodes the root and regular users' PATH variable:
- session-child.c, session_child_run():
/* Set POSIX variables */
if (user_get_uid (user) == 0)
pam_putenv (pam_handle, "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
else
pam_putenv (pam_handle, "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games");
pam_putenv (pam_handle, g_strdup_printf ("USER=%s", username));
pam_putenv (pam_handle, g_strdup_printf ("LOGNAME=%s", username));
pam_putenv (pam_handle, g_strdup_printf ("HOME=%s", user_get_home_directory (user)));
pam_putenv (pam_handle, g_strdup_printf ("SHELL=%s", user_get_shell (user)));I added a dummy path and confirmed that the PATH variable really comes from this code, which answers my questions. And it also means that unlike slim, there's currently no external way to change these paths, other than recompiling the code.
So using ~/.xsessionrc to modify the PATH seems to be the best option so far.
- The reason why lightdm doesn't run /etc/profile is because it doesn't run bash at all. Instead, it directly runs another app "/sbin/lightdm-gtk-greeter". I couldn't figure out where lightdm gets the greeter path from.
Offline