XRDP – Performing a Custom Installation on Ubuntu 16.04

XRDP2_U1604

Hello World,

In our previous post, we have described how to perform a standard installation of xrdp on Ubuntu 16.04. If you are a regular reader, you will have noticed that there is no changes since the previous release of Ubuntu (15.x).  If you follow us, you probably also know that we like to perform a custom installation of xrdp using the latest version of the xrdp package (which is 0.9.0) that available on the Github web site.

In this post, we will check that the current script we have developed to perform the custom installation is still working and provide the desired results.

The Custom Installation Script (version 1.5)

Overview

The xrdp standard installation process under Ubuntu 16.04 is working fine and you will be able to reconnect to existing session out-of-the-box. If you are like us, you might want to check the progress made by the team behind xrdp solution.  To get the bleeding edge xrdp version, you will need to get it from the xrdp Github pages and compile it.

Assumptions

Before running this script, be aware of the following assumptions

  • We have tested the script on Ubuntu 16.04 Alpha 2
  • We are installing Mate-Desktop as alternative Desktop.  If you want to use another, you will have to update the script provided hereafter
  • We have performed the test on a Virtual Machine running on Hyper-V Server

If you want to understand what the script does, you can have a look at this location (Ubuntu 14.04 – Perform a custom XRDP Install (using X11VNC).

Pre-requisites

We assume that you have internet connection on the Ubuntu machine.  The internet connection is needed to download the latest version xrdp package.  If you are not connected to internet, you can still manually download the xrdp package and modify the install-xrdp.sh script accordingly

The script version 1.5

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.

Version 1.5 of the script will try to configure automatically the keyboard layout to be used during xrdp session.  This is experimental.  You can uncomment the lines about keyboard layout at the end of the script before the restart section. The script will also try to configure the system in order to enable multiple users configuration for xrdp. Do not hesitate to provide feedback on these small adjustements and let us know if this is working for you as well.

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

################################################################
 # Script_Name : xrdp-install.sh
 # Description : Perform an automated custom installation of xrdp
 # on ubuntu 15.04 when systemd is used
 # Date : May 2015
 # written by : Griffon
 # Web Site :http://www.c-nergy.be - http://www.c-nergy.be/blog
 # Version : 1.5
 #
 # Disclaimer : Script provided AS IS. Use it at your own risk....
 #
 ##################################################################
 
 
 #-Go to your Download folder
 echo "Moving to the ~/Download folders..."
 echo "-----------------------------------"
 cd ~/Downloads

 #Download the xrdp latest files
 echo "Ready to start the download of xrdp package"
 echo "-------------------------------------------"

 wget https://github.com/neutrinolabs/xrdp/archive/master.zip

 #Unzip xrdp package

 echo "Extracting content of xrdp package..."
 echo "-----------------------------------"
 unzip master.zip

 #Install prereqs for compilation

 echo "Installing prereqs for compiling xrdp..."
 echo "----------------------------------------"
 sudo apt-get -y install autoconf libtool libpam0g-dev libx11-dev libxfixes-dev libssl-dev libxrandr-dev

 #Install the desktop of you choice - I'm Using Mate Desktop

 echo "Installing alternate desktop to be used with xrdp..."
 echo "----------------------------------------------------"
 sudo apt-get -y update
 sudo apt-get -y install mate-core mate-desktop-environment mate-notification-daemon --force-yes
 echo "Desktop Install Done"
 #Configure the Xsession file
 #echo mate-session> ~/.xsession

 #Install the X11VNC
 echo "Installing X11VNC..."
 echo "----------------------------------------"

 sudo apt-get -y install x11vnc

 #Add/Remove Ubuntu xrdp packages (used to create startup service)

 echo "Add/Remove xrdp packages..."
 echo "---------------------------"

 sudo apt-get -y install xrdp
 sudo apt-get -y remove xrdp

 #Compile and make xrdp

 echo "Installing and compiling xrdp..."
 echo "--------------------------------"

 cd xrdp-master
 # needed because libtool not found in Ubuntu 15.04
 # Need to use libtoolize

 sudo sed -i.bak 's/which libtool/which libtoolize/g' bootstrap

 sudo ./bootstrap
 sudo ./configure
 sudo make
 sudo make install

 #Final Post Setup configuration
 echo "---------------------------"
 echo "Post Setup Configuration..."
 echo "---------------------------"

 echo "Set Default xVnc-Sesman"
 echo "-----------------------"

 sudo sed -i.bak '/\[xrdp1\]/i [xrdp0] \nname=Xvnc-Sesman-Griffon \nlib=libvnc.so \nusername=ask \npassword=ask \nip=127.0.0.1 \nport=-1 \ndelay_ms=2000' /etc/xrdp/xrdp.ini

 echo "Symbolic links for xrdp"
 echo "-----------------------"

 sudo mv /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.backup
 sudo ln -s /etc/X11/Xsession /etc/xrdp/startwm.sh
 sudo mkdir /usr/share/doc/xrdp
 sudo cp /etc/xrdp/rsakeys.ini /usr/share/doc/xrdp/rsakeys.ini

 
 

 ## Needed in order to have systemd working properly with xrdp
 echo "-----------------------"
 echo "Modify xrdp.service "
 echo "-----------------------"

 #Comment the EnvironmentFile - Ubuntu does not have sysconfig folder
 sudo sed -i.bak 's/EnvironmentFile/#EnvironmentFile/g' /lib/systemd/system/xrdp.service

 #Replace /sbin/xrdp with /sbin/local/xrdp as this is the correct location
 sudo sed -i.bak 's/sbin\/xrdp/local\/sbin\/xrdp/g' /lib/systemd/system/xrdp.service
 echo "-----------------------"
 echo "Modify xrdp-sesman.service "
 echo "-----------------------"

 #Comment the EnvironmentFile - Ubuntu does not have sysconfig folder
 sudo sed -i.bak 's/EnvironmentFile/#EnvironmentFile/g' /lib/systemd/system/xrdp-sesman.service

 #Replace /sbin/xrdp with /sbin/local/xrdp as this is the correct location
 sudo sed -i.bak 's/sbin\/xrdp/local\/sbin\/xrdp/g' /lib/systemd/system/xrdp-sesman.service

 #Issue systemctl command to reflect change and enable the service
 sudo systemctl daemon-reload
 sudo systemctl enable xrdp.service
 
 
 # Set keyboard layout in xrdp sessions
 cd /etc/xrdp 
 test=$(setxkbmap -query | awk -F":" '/layout/ {print $2}') 
 echo "your current keyboard layout is.." $test
 setxkbmap -layout $test
 sudo cp /etc/xrdp/km-0409.ini /etc/xrdp/km-0409.ini.bak
 sudo xrdp-genkeymap km-0409.ini

 ## Try configuring multiple users system 
 sudo sed -i.bak '/set -e/a mate-session' /etc/xrdp/startwm.sh
 
 echo "Restart the Computer"
 echo "----------------------------"
 sudo shutdown -r now

Set Execute rights on the script

You will need to copy/past the script into a text file in your home directory and save it as xrdp-install.sh.  In order to be able to execute the script, you will need to mark the script as executable as well under you Ubuntu machine.  To make the script executable, you will perform the following action.

 Right-click on the file, go to properties, then select permissions and tick the box allow executable….

xrdp_custom

Click on Picture for better resolution 

or you can use the command line to perform the same action. Open your Terminal console and issue the following command

chmod +x  ~/Downloads/install-xrdp.sh  

(if the file is located in your home directory in the Download Directory. Adapt the path accordingly…)

custom_xrdp_15.04_1.PNG

Click on Picture for better resolution 

Execute the script

You are ready to proceed  with the custom xrdp installation.  As mentioned before,  we assume that you have internet connection and you will be able to download all the necessary packages needed to perform this configuration.

When you are ready, you can execute the script by issuing the following command in the command prompt.

custom_xrdp_15.04_2.PNG

Click on Picture for better resolution 

We assume that you have downloaded or created the file in the your home folder under the Download folders.  If this is not the case, browse to the location and execute the script from there.

Wait for completion of the script.  The machine will reboot automatically when done.

Test your xRDP Connection

It’s time to check if the script ran properly.  The easiest test to perform is to go to your windows machine and perform an rdp connection to the ubuntu machine where you have run the script.  You will need to provide your login information and if the xrdp installation completed successfully, you should see the xRDP login screen (see screenshot)

custom_xrdp_15.04_3.PNG

Click on Picture for better resolution

In the login screen, if you are using a keyboard layout different than EN-US, you will need to check that the script has set the proper keyboard layout for the xrdp login dialog box.  In the username field, check that your keyboard layout is set correctly. If this is not the case, go to the section below to perform a manual configuration of your xrdp keyboard layout.

Finally, to test that reconnection to the same session works, you will need to open a first session, start an application and disconnect.  Try to connect again, and if everything is working as expected, you should see the application you have started in your previous session.

To test that, you can reconnect to the same session, open some applications and then disconnect. You should see that the applications that you have opened are still there up and running.

Manually configure your xRDP keyboard layout

As in the past, the xRDP login screen will use by default an en-us keyboard layout. You remote session will also be using the en-us keyboard layout. The script will try to automatically detect the keyboard layout your are using and try to map this into the xrdp session.  If the script fail to set your keyboard layout properly, you can try to perform the following steps :

In my case, I’m using a Belgian French keyboard, so I had to tell xrdp to use the belgian french keyboard as well.  To do that, you need to perform the following actions :

Step 1 : You go to the /etc/xrdp directory

Step 2 : you issue the command setxkbmap -layout <%your layout%> to define which keyboard map/layout to use

XRDP_15.04_5.PNG

Click on Picutre for better Resolution 

Step 3 : create a copy of the km-0409.ini file into the same directory.

Step 4 : Check that you have a backup of your file by typing the dir or ls command

Step 5 : update the file by issuing the following command sudo xrdp-genkeymap km-0409.ini

XRDP_15.04_6.PNG

Click on Picutre for better Resolution 

Minor Issue

After installing the mate-desktop, you might notice that your ubuntu session (on the console not via xrdp) is a little bit different.  You might see something like this.

U16_Xrdp_4

Click on picture for better resolution

No stress ! This can be fixed quite easily.  Sometimes after installing mate-desktop environment, the ubuntu theme is changed. You can set it back right-clicking on your desktop and select change desktop background.  This will open the appearance applet where you can reset the default Theme (see screenshot below)

U16_Xrdp_5

Click on picture for better resolution

You can see that at the theme level, no option is selected.  Select the default theme for Ubuntu (which is called Ambiance) or any other theme you would like to use.

U16_Xrdp_6

Click on picture for better resolution

After a few seconds, you should see the familiar look n feel of your Ubuntu desktop

U16_Xrdp_7

Click on picture for better resolution

Final Notes

In this post, we have performed a custom installation of xrdp using an updated version of our little script.  The process didn’t changed compared to Ubuntu 15.x.  The same logic still applies.  As mentioned, the script has been updated with some minor improvements and reached version 1.5.  This version of the script tries to detect the keyboard layout in use and try to set it for the xrdp sessions. The previous script was also configuring the system for a single user connection. This version of the script change this setting and configure the system for multiple users by default now.

I hope you will enjoy the small improvements….

Till next time

See ya

28 thoughts on “XRDP – Performing a Custom Installation on Ubuntu 16.04

  1. Hi,
    Thanks again for your great guides. I’m trying to get this working with KDE, so I’ve replaced the mate-session commands with startkde as per your other guide on KDE. When I login, I get stuck at VNC error – problem connecting.

    I can’t see a x11vnc running as my user. Any ideas? Suggestions

  2. I figured out I had x11vnc installed but not vnc4server installed. I am getting a gray screen after I login. Any ideas how to debug it?

  3. Hello Mosin,

    I would need to have a look if the KDE is still working with xrdp. I have seen some reports that indeed the desktop is greyed out starting with (K)UBuntu 15.04
    To check what’s happening, you should have a look at different logs files. You should look at the following files

    ~/.xsession-errors
    /var/log/xrdp.log
    /var/log/xrdp-sesman.log

    and see if any helpful hints can be found

    Hope this help
    Till next time
    See ya

  4. I don’t see ./configure file from *.zip for the below commands:

    sudo ./bootstrap
    sudo ./configure
    sudo make
    sudo make install

  5. First of all, thank you for posting the articles.

    In the meantime, I’m using KDE as default for development, and try to connect from remote windows machine for coding. Would you mind if you can test with Ubuntu 16.04/14.04.2 for Xrdp? I have followed your instruction, but it didn’t work at all with KDE. I will update once I figure it out as well.

    Thank you

  6. Hello Steve,

    This would be challenging…as the kde software has been changed drastically… If we have time, we will investigate on kde as well
    Keep in touch

    Till next time
    See ya

  7. Hello Steve,

    I’m assuming that you have found out how to use the script and how to execute the script.
    The zip file should cotains all the necessary files needed to compile the xrdp software

    Till next time
    See ya

  8. For Ubuntu 14.04, I had to run ‘apt-get upgrade’ when following your instruction, http://c-nergy.be/blog/?p=6717:

    apt-get update
    apt-get upgrade
    apt-get install kubuntu-desktop

    Still, I’m figuring out how to enable KDE with Xrdp on Ubuntu 16.04.

    Another question is that How to use copy&paste between windows and XRDP session? Currently, I’m using mRemoteNG for RDP client in Windows. I CAN’T use copy&paste feature. Would you tell me what RDP client you are using for copy&paste?

    Thank you,

  9. Thanks for the script, I use it on every machine I install.
    There is one minor problem.
    Using your script on a headless server, the script ran into an error in one of the last lines
    test=$(setxkbmap -query | awk -F”:” ‘/layout/ {print $2}’)
    result: Cannot open display “default display”
    The error is logical, as i do not have any display connected.
    xrdp works after that, except the keyboard layout – obviously.
    Thanks

  10. Hello Andres,
    Thank you for the feedback and the visit…
    Did you get the error only on the machine with no monitor or this is a recurring one. If this a recurring one, let me know and i will try to update the script

    If the script has not set the keyboard, you can always set it manually

    Hope this help
    Till next time
    See ya

  11. Hi
    it happens only using your script without previous local login into the mate-desktop. (ubuntu-mate-cloudtop and ubuntu-mate-desktop)
    copying the km-0409.ini does help to get the correct layout, but:
    in the rdp desktop i use virtual-manager and this one use some vnc to control the virtual machines and there i got no keystroke within the RDP.
    I also tried to rsync the user from a working system, no luck.

  12. Hi
    here the results of my investigation.
    If someone is interested in using a headless ubuntu server 16.04 using this script to remote control the computer in combination with an installed virt-manager:
    If the above mentioned error remains – just copy a correct km-0409.ini and replace in the virt-manager the spice interface with the old vnc protocol. After that typing into the windows of the virt-manager works in the rdp session.
    Thanks again for the great script !!!!

  13. Hello Andres,
    as soon as we have time, we will have a look at on to install xrdp on ubuntu server (which requires to install more components including keyboard utilities)
    thank you for all the feedback we will try to improve the content of our blog with this info

    till next time
    See ya

  14. Hi, Griffon,
    I got error message as following, after using the script:

    “VNC error – only supporting 8, 15, 16 and 24 bpp rdp connections”

    do you have any ideas?

    Before trying this script, i’ve tried the ‘easy way’ installation of xrdp, for which i’ve also posted questions.

    Many thanks.

  15. Hi, Griffon,
    Many thanks for your magic script. The error i mentioned in the last post has been solved by your FAQ.

    Thanks a lot for this amazing Blog. I’ve struggled with remote login ubuntu for few days.

    Your guys Rock!

  16. @Yijian

    Hello there, sorry for the late answer but we were quite busy with our projects. The good thing is that you have found the solution to your problem in another post in this blog 🙂

    Thank you for the visit and positive feedback
    Till next time
    See ya

  17. I got it working using this script however running apps still returns “Segmentation fault (core dumped)” in the mate environment.

    “dbg firefox” returns “/usr/bin/firefox”: not in executable format: File format not recognized

    I can run chrome however… some apps are working.. is there any log I can provide you?

  18. @Guillaume,

    Ok, good to hear but what’s different from your installation compared to a standard fresh installation of ubuntu and adding xrdp package
    What have you installed differently than the post describe ? We cannot reproduce your error.

    Till next time
    See ya

  19. can this script be used if i have xfce4 installed already?

    if so how since i can only use xvnc currently.

  20. @Aireagoir,

    either, you simply install the xrdp package, check that the /etc/xrdp/startwm.sh has the line xfce-session and you will be able to connect via xrdp and you will see you xfce interface

    or you can run the script as is and connect to your system via xrdp and have the mate-desktop interface
    or you can modify the script, don’t install the mate desktop and update the the line in the script from mate-session to xfce-session

    Hope this help
    Till next time
    See ya

  21. Hi I made a vmware ubuntu vm using xubuntu and let the script install as default changing nothing but when I try to connect ot the ip of the machine with rdp I can’t it has it’s own ip and is bridged so it should be able to and it starts with the default 192.168 so why can’t I connect no static ip maybe?

  22. it now has a static ip and I can’t connect I used the copy and paste script of xrdp and xubuntu 16.04

  23. Hi,
    after several tries I still cant get the ‘Xvnc-sesman-…’ in my drop down menu of the xrdp start screen, and thus no connection.
    The rest of the script runs fine and w/o any error messages as far as I could see. Only I had to make some adjustments before hand:
    a) due to proxy issues I downloaded the xrdp-master.zip manually (which btw contains the old version 0.6.2!) and let the script run accordingly with out the download, starting with unzip…
    b) second thing I tried: using manually downloaded and extracted version 0.9.1 from https://github.com/neutrinolabs/xrdp/releases/tag/v0.9.1
    same procedure (out commented download and unzip, rest remained as it was)
    in both cases not the right drop down option…
    What can I do?
    PS: before I also had the standard installation of xrpd for ubuntu 16.04 running but it kept closing the windows of the applications directly after starting.

    thanks

  24. @Friederike,

    No clue what the problem could be….

    I think the best option in your case would be (if possible) to have the latest version of Ubuntu installed (Ubuntu 16.10)
    Ubuntu 16.10 ships by default with xrdp package 0.9.x. You simply need to perform a apt-get install xrdp and you should have the software installed and working out of the box

    The script was tested up to xrdp 0.9.0, we will need to check if xrdp version 0.9.1 brings news stuff that might break the installation script.
    If you really want to have it running on Ubuntu 16.04, (and if you didn’t do it yet), try the install on a new machine ( using virtual machine so you can perform snapshots) and ensure that the script is running as expected and that xrdp is working. Then, you could try to compare working and non working system and try to see what could be the problem

    Hope this help

    Till Next Time
    See ya

  25. @Mark Balliet,

    Ok, thank for the info… we never had to install this package on Ubuntu desktop…However, on Ubuntu Server, we had to install indeed additional packages..
    Till next time
    See ya

  26. Hi, thanks for the great article; unfortunately it doesn’t seem to be working for me.

    I just reinstalled Ubuntu 16.04 the other night, so brand new installation – the script ran fine without any errors, but when I went back to my Mac (running Microsoft’s official rdp client), it comes back almost immediately with no connection.

    I made sure my router has port 3389 open to my Linux box, but then I checked netstat -an | grep “3389”, and nothing comes back – maybe the service isn’t running? How can I check on the Linux side?

    Thanks for your time,

    -Bryan

Leave a Reply