xRDP – Install xRDP the easy way on Ubuntu 19.04 (Scripted Installation – Version 0.6)

Hello world,

Finally, it’s time to reveal the updated version of the famous standard xrdp installation script (i.e. Std-Install-xrdp-0.6.sh).  After spending some time in performing a manual installation and finding some issues in Ubuntu 19.04, we have been improving the script in order to provide a better solution when installing xRDP packages and still taking into accounts the user experience aspect that’s left out from the manual installation process.  

In our previous posts, we have described our installation approach (manual first) and then we have explained, described and fixed all the small issues we have encountered when installing xRDP on top of Ubuntu 19.04.  To know more about our findings, you can have a look at the following posts 

The updated version of the standard installation script basically integrates all these findings and the end result is an optimized installation script which still provide the best user experience when using xRDP on top of Ubuntu operating system. 

Time to reveal this updated version… Let’s go ! 

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

The Standard Installation Script – Version 0.6

Overview

The standard installation script aims to simplify xrdp installation process while performing some additional post configuration tasks that will provide the most relevant user experience. The release of Ubuntu 19.04 has forced us to update the script.  Initially, the script would only include support for Ubuntu 19.04 and would have been labelled version 0.5.4.  However, because some interesting changes have been made in the code, we have decided to move to version 0.6. 

First, we have updated the code that was used to enable Ubuntu Desktop with Dock and Yaru theme when performing the remote connection.  The code has been simplified and reduced quite a lot through the usage of xsessionrc X startup script.  Then, a positive side effect of using this approach has been discovered.  There is no need to fix the gdm login look n’ feel between local session and remote session using complex code.  Again, xsessionrc X startup script fixes the issue which help reducing number of lines in the code.    

Sound redirection function has been re-written because the xrdp-pulseaudio-installer package (which was used in the previous version of the script) is not available on Ubuntu 19.04.  So, instead of waiting for a possible release of this package, we have modified the code for the sound redirection part and we are now compiling directly from the sources.. 

Prerequisites and assumptions

We assume that you have internet connection available and that you are indeed running one of the following version of Ubuntu 

  • Ubuntu 18.04 (up to Ubuntu 18.04.2)
  • Ubuntu 18.10
  • Ubuntu 19.04 
  • We have performed the test on a Virtual Machine running on Virtual box (on Windows 2012 R2) with Sound enabled !!!
  • No additional Desktop interface will be used. The remote desktop session will display the Ubuntu tweak Gnome Desktop interface

The script version 0.6

Important Note :

If you copy/paste the script, you might encounter some issues because font formatting might be not maintained during the copy/paste operation. Please ensure that format is  accurate before launching the script. A downloadable version of the script is available at the bottom of the post

Disclaimer : As usual, use this at your own risk !!

#!/bin/bash
#####################################################################################################
# Script_Name : Std-Xrdp-install-0.6.sh
# Description : Perform an automated standard installation of xrdp
# on ubuntu 18.04 and later
# Date : October 2018
# written by : Griffon
# Web Site :http://www.c-nergy.be - http://www.c-nergy.be/blog
# Version : 0.6
# History : 0.6 - Added support for Ubuntu 19.04 
#               - New code for Look'n feel using xsessionrc method
#               - New code for enabling Sound Redirection - compiling from source 
#               - Removed -g parameter 
# : 0.5.3 - Using Unoffical xRDP packages for Ubuntu 18.04.2 issue
# : 0.5.2 - Quick Fix for Ubuntu 18.04.2
# : 0.5.1 - Add support to Ubuntu 18.10 
# : 0.5 - Add logic to enable sound redirection 
# - re-write code logic to include functions
# - Removed support for Ubuntu 17.10 as reached end of support
# : 0.4 - Add logic to fix GDM lock screen + minor change
# : 0.3 - Adding logic to fix theme and extensions for any users login through xrdp
# 0.2 - Added Logic for Ubuntu 17.10 and 18.04 detection 
# - Updated the polkit section
# - New formatting and structure 
# 0.1 - Initial Script 
# Disclaimer : Script provided AS IS. Use it at your own risk....
####################################################################################################
#---------------------------------------------------#
# Detecting if Parameters passed to script .... 
#---------------------------------------------------#

while getopts s:u: option 
do 
case "${option}" 
in 
s) fixSound=${OPTARG};;
u) unofficialRepo=${OPTARG};; 
esac 
done

#---------------------------------------------------#
# Script Version information Displayed #
#---------------------------------------------------#

echo
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m ! Standard XRDP Installation Script - Ver 0.6                 !\e[0m"
/bin/echo -e "\e[1;36m ! Written by Griffon - May 2019 - www.c-nergy.be              !\e[0m"
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
echo

#--------------------------------------------------------------------------#
# -----------------------Function Section - DO NOT MODIFY -----------------#
#--------------------------------------------------------------------------#

#-----------------------------------------------------#
# Function 0 - Quick and Dirty Patch Ubuntu 18.04.2 #
#-----------------------------------------------------#

install_xservercore() 
{
echo
/bin/echo -e "\e[1;33m !----------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Installing xserver-xorg-core Packages...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !----------------------------------------------------------!\e[0m"
echo
sudo apt-get install xserver-xorg-core -y
echo
/bin/echo -e "\e[1;33m !----------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Installing xserver-xorg-input-all pkg...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !----------------------------------------------------------!\e[0m"
echo
sudo apt-get -y install xserver-xorg-input-all 
}

#---------------------------------------------------#
# Function 1 - Install xRDP Software.... 
#---------------------------------------------------#

install_xrdp() 
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Installing XRDP Packages...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo
sudo apt-get install xrdp -y 
}

#---------------------------------------------------#
# Function 2 - Install Gnome Tweak Tool.... 
#---------------------------------------------------#

install_tweak() 
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Installing Gnome Tweak...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo
sudo apt-get install gnome-tweak-tool -y
}

#--------------------------------------------------------------------#
# Fucntion 3 - Allow console Access ....(seems optional in u18.04)
#--------------------------------------------------------------------#

allow_console() 
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Granting Console Access...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo
sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config
}

#---------------------------------------------------#
# Function 4 - create policies exceptions .... 
#---------------------------------------------------#

create_polkit()
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Creating Polkit File...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo

sudo bash -c "cat >/etc/polkit-1/localauthority/50-local.d/45-allow.colord.pkla" <<EOF
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes

[Allow Package Management all Users]
Identity=unix-user:*
Action=org.debian.apt.*;io.snapcraft.*;org.freedesktop.packagekit.*;com.ubuntu.update-notifier.*
ResultAny=no
ResultInactive=no
ResultActive=yes
EOF

}

#---------------------------------------------------#
# Function 5 - Fixing Theme and Extensions .... 
#---------------------------------------------------#

fix_theme()
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Fix Theme and extensions...Proceeding... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo
sudo sed -i.bak "4 a #Improved Look n Feel Method\ncat <<EOF > ~/.xsessionrc\nexport GNOME_SHELL_SESSION_MODE=ubuntu\nexport XDG_CURRENT_DESKTOP=ubuntu:GNOME\nexport XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg\nEOF\n" /etc/xrdp/startwm.sh
echo
}

#---------------------------------------------------#
# Function 6 - Enable Sound Redirection .... 
#---------------------------------------------------#

enable_sound()
{
echo
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m ! Enabling Sound Redirection... !\e[0m"
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m"
echo

# Step 1 - Enable Source Code Repository
sudo apt-add-repository -s 'deb http://be.archive.ubuntu.com/ubuntu/ '$codename' main restricted'
sudo apt-add-repository -s 'deb http://be.archive.ubuntu.com/ubuntu/ '$codename' restricted universe main multiverse'
sudo apt-add-repository -s 'deb http://be.archive.ubuntu.com/ubuntu/ '$codename'-updates restricted universe main multiverse'
sudo apt-add-repository -s 'deb http://be.archive.ubuntu.com/ubuntu/ '$codename'-backports main restricted universe multiverse'
sudo apt-add-repository -s 'deb http://be.archive.ubuntu.com/ubuntu/ '$codename'-security main restricted universe main multiverse'
sudo apt-get update

# Step 2 - Install Some PreReqs
sudo apt-get install git libpulse-dev autoconf m4 intltool build-essential dpkg-dev -y
sudo apt build-dep pulseaudio -y

# Step 3 - Download pulseaudio source in /tmp directory - Do not forget to enable source repositories
cd /tmp
sudo apt source pulseaudio

# Step 4 - Compile
pulsever=$(pulseaudio --version | awk '{print $2}')
cd /tmp/pulseaudio-$pulsever
sudo ./configure

# step 5 - Create xrdp sound modules
sudo git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git
cd pulseaudio-module-xrdp
sudo ./bootstrap 
sudo ./configure PULSE_DIR="/tmp/pulseaudio-$pulsever"
sudo make

#Step 6 copy files to correct location (as defined in /etc/xrdp/pulse/default.pa)
cd /tmp/pulseaudio-$pulsever/pulseaudio-module-xrdp/src/.libs
sudo install -t "/var/lib/xrdp-pulseaudio-installer" -D -m 644 *.so
sudo install -t "/usr/lib/pulse-$pulsever/modules" -D -m 644 *.so
echo

}


fix_ssl() 
{ 
echo 
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m" 
/bin/echo -e "\e[1;33m ! Fixing SSL Cert Issue ...                   !\e[0m" 
/bin/echo -e "\e[1;33m !---------------------------------------------!\e[0m" 
echo 
sudo adduser xrdp ssl-cert 
}
#--------------------------------------------------------------------------#
# -----------------------END Function Section -----------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#------------ MAIN SCRIPT SECTION -------------------# 
#--------------------------------------------------------------------------#
#---------------------------------------------------#
#-- Step 0 - Try to Detect Ubuntu Version.... 
#---------------------------------------------------#

version=$(lsb_release -sd) 
codename=$(lsb_release -sc)

echo
/bin/echo -e "\e[1;33m |-| Detecting Ubuntu version \e[0m"

if [[ "$version" = *"Ubuntu 18.04"* ]];
then
/bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m"
echo
elif [[ "$version" = *"Ubuntu 18.10"* ]];
then
/bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m"
echo
elif [[ "$version" = *"Ubuntu 19.04"* ]];
then
/bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m"
echo
else
/bin/echo -e "\e[1;31m !------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;31m ! Your system is not running Ubuntu 18.04 Edition and later !\e[0m"
/bin/echo -e "\e[1;31m ! The script has been tested only on Ubuntu 18.04 and later !\e[0m"
/bin/echo -e "\e[1;31m ! The script is exiting... !\e[0m" 
/bin/echo -e "\e[1;31m !------------------------------------------------------------!\e[0m"
echo
exit
fi

/bin/echo -e "\e[1;33m |-| Detecting Parameters \e[0m"

#Detect if argument passed
if [ "$fixSound" = "yes" ]; 
then 
/bin/echo -e "\e[1;32m |-| Sound Redirection Option...: [YES]\e[0m"
else
/bin/echo -e "\e[1;32m |-| Sound Redirection Option...: [NO]\e[0m"
fi

if [ "$unofficialRepo" = "yes" ]; 
then 
/bin/echo -e "\e[1;32m |-| Unofficial Repo...........: [YES]\e[0m"
else
/bin/echo -e "\e[1;32m |-| Unofficial Repo...........: [NO]\e[0m"
fi
echo

#---------------------------------------------------------#
# Step 2 - Executing the installation & config tasks .... #
#---------------------------------------------------------#

echo
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m ! Installation Process starting.... !\e[0m"
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
echo
/bin/echo -e "\e[1;33m |-| Proceed with installation..... \e[0m"
echo

if [[ "$version" = *"Ubuntu 18.04.2"* ]];
then
/bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m"
echo
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m ! Applying Installation Patch for Ubuntu 18.04.2 Only !\e[0m"
/bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m"
echo
if [ "$unofficialRepo" = "yes" ];
then
/bin/echo -e "\e[1;32m => Downloading Unofficial xRDP packages (Thiago Martins) !\e[0m"
echo
sudo add-apt-repository ppa:martinx/xrdp-hwe-18.04 -y
sudo apt-get update
install_xrdp
install_tweak
allow_console
create_polkit
fix_theme
fix_ssl
else
/bin/echo -e "\e[1;32m => Downgrading to previous xserver-xorg-* packages !\e[0m"
echo
install_xservercore
install_xrdp
install_tweak
allow_console
create_polkit
fix_theme
fi
else
install_xrdp
install_tweak
allow_console
create_polkit
fix_theme
fix_ssl
fi

if [ "$fixSound" = "yes" ]; 
then 
enable_sound
fi

#---------------------------------------------------#
# Step 9 - Credits .... 
#---------------------------------------------------#
echo
/bin/echo -e "\e[1;36m !------------------------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m ! Installation Completed !\e[0m" 
/bin/echo -e "\e[1;36m ! Please test your xRDP configuration.A Reboot Might be required... !\e[0m"
/bin/echo -e "\e[1;36m ! Written by Griffon - May 2019 - Ver 0.6 - Std-Xrdp-Install-0.6.sh !\e[0m"
/bin/echo -e "\e[1;36m ! !\e[0m"
/bin/echo -e "\e[1;36m ! Thanks to Thiago Martins who provided Updated xRDP packages for 18.04.2 :-) !\e[0m"
/bin/echo -e "\e[1;36m !------------------------------------------------------------------------------!\e[0m"
echo

How to Use the Script

Again, script usage is basically the same as the previous versions.  We will not go into details here but simply explain how to use it and how to execute it. 

Step 1 – Set Execute Right on the script

Download the Std-Xrdp-install-0.6.sh script to your system, extract content and mark it as executable . To do this, perform the following action in a terminal console

chmod +x  ~/Downloads/Std-Xrdp-Install-0.6.sh

Note : Adjust the path where the Std-Xrdp-Install-0.6.sh script to reflect your environment

Step 2 – How to execute the script ? 

With this version of the script, you can decide to pass no parameters or pass 2 parameters (which are -s  -u). The following section explains what are these options   

Standard way

To perform a standard installation, you execute the script with no parameters.  Open a Terminal console, browse to the location where the script has been downloaded and issue the following command 

 ./Std-Xrdp-Install-0.6.sh

When the xrdp installation package will start, you be requested to enter your password. Provide the password and proceed with the installation. Wait for completion of the script.  The machine will not reboot automatically when done so you can review the actions performed by the script….

This installation mode will downgrade to older Ubuntu packages that can be used with xRDP and xorgxrdp packages if you are running Ubuntu 18.0.4.2.  This installation mode uses the quick and dirty fix…. 

Advanced way – Sound redirection 

If you want to use sound redirection within your remote session, you will need to run the script with the -s parameter.  When the -s parameter is passed, the sound redirection function will be executed and all the necessary actions would be performed by the script that will allow sound redirection.  To enable this additional feature within your remote desktop session, you will need to user the following syntax

To implement the sound redirection fix  within the xrdp session, use this syntax

./Std-Xrdp-Install-0.6.sh -s yes

When script execution is completed, the machine will not reboot so you can review the installation and detect possible elements that’s preventing the script execution.  At completion, it’s recommended to reboot the machine so the changes made to the system can be applied accordingly. 

Custom Option – using unofficial xRDP packages (use it if running Ubuntu 18.04.2)

If you are running Ubuntu 18.04.2, you know that a small issue has been detected when installing the standard xrdp packages.  The issue will prevent the installation of the xorgxrdp package which will result in not being able to perform remote connection.  The script will detect this operating system and will take corrective actions in order to ensure that xrdp functionality will work after the installation process. 

However, the remediation process implies that some packages will be downgraded to a working version.  Some people might not like this approach.  So, we have included in the version 0.6 of the script the possibility to use unofficial xRDP packages that will be compatible with Ubuntu 18.04.2 while keeping the most recent version of needed packages to have xrdp installed properly. 

 If you want to use the unofficial xRDP packages, you will need to issue the following command 

./Std-Xrdp-Install-0.6.sh -u yes

This command will add some additional ppa repositories and will use these packages to perform the xRDP installation.  It’s important to note that this option will only work when running the script on Ubuntu 18.04.2.  The script will check if you are running this version specifically and if you have used the -u option, unofficial packages will be used.

Obviously, you can combine the -s and -u parameters if you are running Ubuntu 18.04.2 operating system and you want to use sound redirection as well… 

./Std-Xrdp-Install-0.6.sh -u yes -s yes

Step 3 – Test your configuration 

After the script has run and after the reboot, it’s time to test and see if you can indeed perform a smooth remote connection to your Ubuntu machine.  Remember that a user can either be logged on locally or logged on remotely on the machine when working with xRDP solution.  If the user, performing the remote connection, is logged into the system locally the remote connection will start but will be terminated immediately.  This is the way it works nowadays. 

So, ensure that the user performing the test is not locally logged on, start your favourite remote desktop client and perform your connection.  You will be presented with the green login screen. Enter your credentials.  If everything is ok, you should then see your Ubuntu desktop displayed in the remote session.  You should be good to go and start performing some of your work.  If you disconnect from your session, you should be able to reconnect to the same session and proceed with the work you were doing.   

Download the Script 

Please download the script :  Std-Xrdp-Install-0.6.zip

Final Notes

This is it for this post !   

We have included Ubuntu 19.04 support in our famous easy to use installation script and we managed to bring some improvements as well.  We are quite happy with the results.  The next step is to publish the version of the script that can be used to perform an installation from source files.  Obviously, we will integrate the same improvements in the custom installation script.  If you have some time, give it a try and provide feedback.  If you find a bug or an issue with the script, let us know as well so we can try to fix it 

Stay tuned as other stuff are coming as well…..

That’s is for today 

Till next time 

 

 

 

2 thoughts on “xRDP – Install xRDP the easy way on Ubuntu 19.04 (Scripted Installation – Version 0.6)

  1. Thanks for this. Will the script work on any of the Ubuntu 19.04 flavors? I would like to use xRDP on Kubuntu, but may use another flavor if I need to.
    Also, what is the procedure for connecting to a currently logged in user session on the local desktop?

    Thanks again for all your hard work!

    buzz

  2. @Buzzra,

    These scripts have been specifically designed and tested for Ubuntu Operating system. In the past we were providing scripts or procedure in order to use and configure xRDP on other Ubuntu Flavors. Because of time constraint, we decided to focus on one Ubuntu flavor only and we have tried to provide the best install/config script for it.

    As far as we know, it’s not possible to use xRDP software in order to connect to the console session (currently logged on user on the local desktop). Actually, you cannot have the same user logged on locally and logged on remotely at the same time. This will fail and you will get disconnected immediately if trying so. A single user can be logged either on the local computer or through a remote session

    Hope this help
    Till next time
    See ya

Leave a Reply