xRDP – Working with Environment variables in Ubuntu 19.04

Hello World, 

Since a few weeks now, we have been working on xRDP and we have provided more and more information about how to install xRDP software package but most importantly how to provide a better user experience by customizing the Desktop interface and getting rid of some of the popups generated by the Polkit framework solution.  We also made a step forward in proposing a new visual aspect for the xRDP login screen.  We are not big fan of the green/grey color combination for the xRDP login and we came up with our own version.  

In this post, we will have a look at the environment variable which are different between the local session and the remote session when using xRDP.  This is a recurring question we are receiving and it’s maybe time to explain the behavior and offer some ways to fix this 

Let’s do this ! 

If you want to know more about xRDP and Ubuntu 19.04 and all the small improvements made, you can read the following posts 

To ease the installation of xRDP and perform all the necessary post configuration tasks, you can use one of the following scripts 

Note :  Please always check this page, to get the latest version of the script

Generic Problem description 

To describe the issue, let’s assume the following situation. 

A user locally connected to the Ubuntu machine is requested to check the xRDP version running on the system.  To obtain this information, the user simply issue the following command in a terminal console

xrdp -v 

The following output (or similar) should be displayed and the user can see that xrdp version is set in our example to version 0.9.9

Click on picture for better Resolution

So, now, the user perform a remote connection to the system using xRDP solution and needs to check again the xRDP version because he couldn’t remember that.  The user will then open the terminal session and execute again the following command 

xrdp -v 

However, this time the following output is displayed

Click on picture for better resolution

The output indicates two possible causes of this issue.  Either the user has no admin privileges to display this information (but he can when logged on locally!!) or because the /usr/sbin/xrdp is not included in the PATH environment variable.  So, based on the message, in order to obtain the same information when remotely connected to an Ubuntu machine, the user will need to execute one of the following commands

/usr/local/sbin/xrdp -v

Click on picture for better resolution

or 

sudo xrdp -v 

Click on picture for better resolution

 

This situation describes exactly the problem.  Depending the way a user is connected, different commands needs to be executed in order to obtain the same information. While not a show stopper, it’s generates again an annoyance for the users.   The issue here is related to environment variables which are not loaded “correctly” in the remote session.   Again, to improve the user experience, this post will try to explain how to overcome this minor annoyance. 

Note : 

The situation will be different based on the version of Ubuntu you are running.  We have noticed that this issue would exist in Ubuntu 18.04 for example but the issue does not seems to exist when running Ubuntu 19.04 and that you have been using the default xRDP packages available in the Ubuntu repositories.  This post will try to provide a generic solution that should work for any Ubuntu version you might be running 

Possible Solution

What we found out !

As we were working on new version of our famous installation scripts, we have performed a custom installation (see here) and we have noticed that the xRDP version was set to 0.9.10 while a standard installation using the Ubuntu xrdp packages would set the version to 0.9.9.  The following screenshot shows that the same problem exists with the latest version of xRDP packages

Click on picture for better resolution

What’s interesting here is that we have edited the /etc/xrdp/startwm.sh file and we have noticed that a new section has been added at the bottom.  This section is basically tackling the environment variable issues.  There are basically multiple options available 

  • we can call the file containing the environment variable (. /etc/profile)
  • we can define the necessary value for the PATH variable and export it within the remote session or,
  • we can update the /etc/pam.d/xrdp-sesman file by adding a line that would load the env variables
  • we could use a X startup script to set $PATH variable with the correct information 

Click on picture for better resolution

Ubuntu 19.04 Scenario

So, in Ubuntu 19.04, when performing a standard installation, environment variable are available within the remote session. However, if performing a custom installation on Ubuntu 19.04, where the latest package version is downloaded and installed (i.e. 0.9.10), the environment variable are not available anymore…..

(xRDP 0.9.9 on Ubuntu 19.04) 

Click on picture for better resolution 

(xRDP 0.9.10 on Ubuntu 19.04)

Click on picture for better resolution

Based on the installation method, you might have the environment variable available within your remote session or not.  If they are not available, you will need to perform an additional post configuration action on your system.  The next section explains what’s needs to be done… 

Ubuntu 18.04, Ubuntu 18.10 Scenario

When performing the standard installation of xRDP using our famous script (see here), you are basically using the Ubuntu packages which will install the version 0.9.5 of xRDP on your system (or if specified you will be using the unofficial xRDP packages – see here for more info).  The script will also ensure that the Ubuntu Desktop with Dock will be available within the remote session.  Everything should be working ok except the environment variables.   We have been testing different solutions and we think that the best approach (because we can standardize it) would be to use the /etc/pam.d/xrdp-sessman option

Modifying this file by adding the following line will ensure that environment variable will be read and will be available within the remote desktop session 

session required pam_env.so readenv=1 user_readenv=0

After restarting the xrdp service, the environment variable should be usable within your remote session.  The following screenshots illustrate this.  The /etc/pam.d/xrdp-sessman file, accordingly modified, make it possible to execute standard commands within the remote session 

Click on picture for better resolution 

Ubuntu 19.04

Standard Installation

When performing the standard installation of xRDP using our famous script (see here), again you will be using the official Ubuntu packages.  The script will again take care of the post configuration actions and surprisingly the environment variable are available and you can work with them out of the box.    

Click on picture for better resolution 

Custom Installation

When performing the custom installation of xRDP using our famous script (see here), you are basically compiling xRDP from the sources and you might end up with the latest version of the xRDP solution.  At time of writing, we performed the custom installation and we ended up with the xRDP version 0.9.10 

Click on picture for better resolution

Again, the best approach seemed to use the /etc/pam.d/xrdp-sesman file.  Adding the following line and restarting the xRDP services made the environment variable available within the remote session.  

session required pam_env.so readenv=1 user_readenv=0

Click on picture for better resolution 

Again, there might be other ways to achieve the same results.  We are looking for something that working 100 % and easy to maintain because we want to integrate this additional configuration tweak in our famous installation scripts.  At the moment, it seems that the best option to always have environment variables loaded is to use the /etc/pam.d/xrdp-sesman configuration tweak whatever the version of Ubuntu you are running.   

Final Notes

This is it for this post !   

To summarize, we found out that depending on the Ubuntu release and depending on the xRDP version, different results can be achieved.  However, we have to notice that most of the time environment variable are not usable within a remote session.  This is probably not a major issue but could become an annoyance for some advanced users.  To further improve the user experience, and based on our findings while installing xRDP 0.9.10, it seems that the best way to include the variable within the remote session consist in updating the /etc/pam.d/xrdp-sesman file.  This approach seems to always work. 

The current version of our famous scripts are not modifying the /etc/pam.d/xrdp-sesman file (yet !). This means that a manual action might be needed in order to enable this functionality.  The next version of the script will include these findings and this will  again help achieving the best user experience while simplifying the xRDP installation. 

We are already working on the new version of the script and we can already tell you, it will look better than ever….. :-).  Expect some important changes in the coming version of the script.  Initially, we wanted to ship it with the release of Ubuntu 20.04. However, based on the progress status, we think that the scripts release date might still occur when Ubuntu 19.10 will be released (or sooner…)

Stay tuned

Till next time 

See ya 

 

4 thoughts on “xRDP – Working with Environment variables in Ubuntu 19.04

  1. Hi, do you know how to enable nvidia-settings during XRDP session?

    In console session, everything works fine, but here not:

    ERROR: Unable to load info from any available system
    (nvidia-settings:4551): GLib-GObject-CRITICAL **: 11:50:49.753: g_object_unref: assertion ‘G_IS_OBJECT (object)’ failed
    ** Message: 11:50:49.757: PRIME: No offloading required. Abort
    ** Message: 11:50:49.757: PRIME: is it supported? no

    Do you have any solution?

  2. @Mateusz,

    We do not have systems running with NVIDIA devices… We cannot really help here.. .However, xRDP is known to have some issues with nvidia and some specific configuration might be needed indeed
    If time permit, we will try to check that……and try to find some info about such settings

    Hope this help
    Till next time

  3. My problem is my BT keyboard. It works with xdrp without any problems, but it is a part of my TV domain. I mean, TV takes BT connection, and somehow delegates every action to linux equipped laptop. The problem is, ’cause samsung way of controlling BT keyboard is very poor and ubuntu doesn’t see any BT device because it’s TV controlled. So no way to change any keyboard settings. Is it possible to rearrange devices control administration and delegates it back to linux?

  4. @Michale,

    Thank you for visiting our blog and providing some feedback. Not sure we understand your question… are you looking for a way to enable/disable blueTooth applet from xrdp session ? are you being blocked by the Polkit feature…?

    waiting for some feedback
    Till next time
    see ya

Leave a Reply