9

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: Screenshot

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
7

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
| improve this answer | |
  • Yes, without this, xrdp sessions were missing all the variables defined in my /etc/environment ! – wisbucky Apr 18 '19 at 17:28
5

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
| improve this answer | |
  • The "environment" file is normal, adding the correct paths to ~/.bashrc makes the commands run on the terminal but still not working on the Ubuntu "Package Installer". I couldn't find the root of the problem but i have a solution now, i created a symbolic link in /bin/ to each program required (ldconfig, etc)... this is probably a security breach so i will leave this question open in case anyone haves a better solution. – Ivan Castellanos Jan 3 '12 at 22:03
  • @IvanCastellanos: I'm not sure what you mean by "package installer," as there's no program with that exact name AFAIK. Could you describe the steps you're taking to install packages? And is this a GUI or command-line installer? – Scott Severance Jan 3 '12 at 23:23
  • Sorry, i mean "GDebi Packpage Installer" (GUI). – Ivan Castellanos Jan 4 '12 at 4:45
  • @IvanCastellanos: Do you launch it as gksudo gdebi-gtk /full/path/to/package.deb? I've found it to be a bit picky. If so, then it should inherit the environment it's launched from. – Scott Severance Jan 4 '12 at 5:49
3

Full disclosure: I don't use Ubuntu... but I had the same issue with Debian.

xrdp launches /etc/xrdp/startwm.sh (unless Ubuntu has modified this location). I added this line:

. /etc/profile

to the top of /etc/xrdp/startwm.sh and the PATH is now set correctly.

For Ubuntu, adding

. /etc/environment

to the top of /etc/xrdp/startwm.sh might do the same.

| improve this answer | |
2

This stumped me for a while too. /etc/environment isn't a shell script, so you can't call it as one. What worked for me was to edit the xrdp session manager "sesman" script in pam. I added the "session" line to my /etc/pam.d/sesman file:

#%PAM-1.0
session required pam_env.so readenv=1 user_readenv=0
@include common-auth
@include common-account
@include common-session
@include common-password

This makes the session manager load the /etc/environment file at login.

| improve this answer | |
1

In theory adding

. /etc/environment

would work but it doesn't. I just put it at the top of my .bashrc to correct the problem

| improve this answer | |
1

Thanks to the previous answers I came to such a solution:

cat /etc/xrdp/startwm.sh | sed "s/. \/etc\/X11\/Xsession/. \/etc\/environment/" > ./startwm.sh && echo ". /etc/X11/Xsession" >> ./startwm.sh && sudo mv ./startwm.sh /etc/xrdp/startwm.sh && sudo chmod 755 /etc/xrdp/startwm.sh

May be not the most optimal but working (Ubuntu 12.04).

| improve this answer | |
1

@ John: I believe you need to check your /etc/xrdpstartwm.sh - the first lines in mine reads,

if [ -f /etc/X11/xinit/xinitrc ]
then
    . /etc/X11/xinit/xinitrc
    exit 0
fi**

That means that if /etc/X11xinit/xinitrc exists, that file will be executed instead - and it won't help much to add the

. /etc/environment

to /etc/xrdpstartwm.sh. :-)

/Per Hertz

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.