Ubuntu has a different PATH when accessed over XRDP session
Noob here: I have a problem, when i access my server via SSH, the $PATH is correct
root@ks391320:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
But when i open my server via XRDP session and go to the terminal it shows an incorrect PATH:
root@ks391320:~# echo $PATH
/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin
Screenshot of both:
And this creates an issue because when I try to install something using the "Package Installer" it shows this error (among others)
dpkg: warning: 'ldconfig' not found in PATH
For Ubuntu-18.04, edit /etc/pam.d/xrdp-sesman
and enter the following lines at beginning:
session required pam_env.so readenv=1 envfile=/etc/environment
session required pam_env.so readenv=1 envfile=/etc/default/locale
1
The system-wide default PATH is defined in /etc/environment
. First, verify that it's set to a sane value. For reference, here's mine, which is the same as a default install:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
2
If /etc/environment
is sane and you're still having issues, you can override the default PATH in ~/.bashrc
. For example, I have this in my .bashrc which appends a directory to my PATH if and only if it exists and is not already in my PATH:
if [ -d "$HOME/bin" ]; then
if [[ $PATH =~ $HOME/bin ]]; then :
else export PATH="$HOME/bin:$PATH"
fi
fi
Since it appears from your screenshot that you've enabled root logins, be sure to set root's .bashrc, as well. (By the way, since root can't login by default in Ubuntu, this configuration is presumably less tested and might possibly be related to your problem.)
3
If the first two methods fail, then check whether your XRDP client is doing something exotic. If so, you'll have to either configure it to work normally or identify a way to work around it.
Update
I've been doing some looking around the system. You can find all the places on your system that specify a PATH with the following command (the sudo
is there because some files under /etc
are unreadable by normal users):
sudo egrep -nr '\bPATH' /etc | less
I think it's safe to ignore many of those places, resulting in the following command:
sudo egrep -nr '\bPATH' /etc | egrep -v '^/etc/(init|rc|ppp|bash_c)' | egrep -v '^Binary' | less
One file that looks possible (though I really don't know too much about it) is /etc/login.defs
. You might take a look at it.
In addition, you could grep your dotfiles as well:
egrep -nr '\bPATH' $HOME/.* | less