Using xRDP for Remote Desktop Access Last Modified: 2015-12-05
Enabling Remote Desktop Protocol connectivity using xRDP on Ubuntu 14.04 LTS and the xfce window manager.
xRDP Remote Desktop Linux

This document contains the steps for enabling remote desktop access to a linux server using the Remote Desktop Protocol. The server operating system used here is Ubuntu Server 14.04 LTS.

xRDP Server

Install and Configure xRDP

Install xrdp: apt-get install xrdp.

By default, the X11 vnc sessions started through xrdp are not terminated on logout. With the default configuration, each connection creates a new session which causes X11 sessions to pile up until no more connections are accepted. To prevent X11 sessions from piling up, make a configuration change to /etc/xrdp/sesman.ini. Add a new parameter with value -once in the [Xvnc] section, e.g.:

[Xvnc]
param1=-bs
param2=-ac
param3=-nolisten
param4=tcp
param5=-localhost
param6=-dpi
param7=96
param8=-once

Enabling connections to existing sessions requires modifying the xRDP source code to use x11vnc instead of xvnc4 as the back-end. See this post for more information.

Install and Configure Window Manager

The default window manager gnome does not work well with RDP on Ubuntu 14.04. In my case I only get a blank raster background with an X-shaped cursor when using gnome over xRDP and the following errors in ~/.xsession-errors

gnome-session[8092]: WARNING: software acceleration check failed: Child process exited with code 1
gnome-session[8092]: CRITICAL: We failed, but the fail whale is dead. Sorry....

The solution is to use a window manager that does not require acceleration, like Xfce.

  • To install xfce, run apt-get install xfce4.
  • To configure xfce4 for the current user (both local and remote logins), add xfce4-session to the file ~/.xsession (create the file if it does not exist).

The gnome fallback session is sometimes reported to be working, but apparently it is broken on recent Ubuntu versions (I get the same blank raster screen problem as with the default gnome version).

  • To install the gnome fallback, run sudo apt-get install gnome-session-fallback
  • To configure gnome fallback for the current user (both local and remote logins), add gnome-session --session=gnome-fallback to the file ~/.xsession (create the file if it does not exist).

Alternatively, to configure the alternative window manager for all xRDP connections and not local logins, modify /etc/xrdp/startwm.sh to start the alternative window manager instead of the default, e.g.:

#!/bin/sh  

if [ -r /etc/default/locale ]; then
  . /etc/default/locale
  export LANG LANGUAGE
fi

# Changed xrdp wm to xfce4. Original command:
# . /etc/X11/Xsession
xfce4-session

Connecting with RDP

To make sure the configuration changes take effect, restart xrdp: sudo service xrdp restart.

Connect using a remote desktop client. In the login screen select module sesman-Xvnc.

Killing Orphans

The X11 sessions are still not properly terminated if a user does not log out properly (closes the RDP window) or when the network connection fails. Also the log-out functionality (at least in xfce) does not always terminate the instance properly (leaving the RDP window open on the client and the session active on the server). Note that the orphaned sessions aren’t cleared even when restarting xrdp.

To find running Xvnc processes, run ps aux|grep Xvnc, take note of the PIDs and the display number in the Xvnc command, e.g. 10 in Xvnc :10 .... The X11 session number range is defined for xrdp in /etc/xrdp/sesman.ini (X11DisplayOffset and MaxSession).

[Sessions]
X11DisplayOffset=10
MaxSession=10
KillDisconnected=0 #This option is currently ignored
IdleTimeLimit=0 #This option is currently ignored
DisconnectedTimeLimit=0 #This option is currently ignored

To kill the orphan session, kill the process using the pid from the ps command. In addition, you must remove the session and session lock files.

sudo kill -9 <pid>
rm /tmp/.X11-unix/X<display>
rm /tmp/.X<display>-lock

If your system stores the pid of the Xvnc process in ~/.vnc/<host>:<display>.pid, then you can simply call vncserver -kill :<display>. If not, you’ll get the following error when executing the above command:

Can’t find file /home/<user>/.vnc/<host>:<display>.pid
You’ll have to kill the Xvnc4 process manually

Tweaks

Keyboard Mappings

Xrdp does not pick up the correct key map by default from the server if the xrdp layout file is not present on the system (for example finnish).

For finnish keyboard layout the easiest way is to copy the swedish keyboard layout as the finnish layout:
cp /etc/xrdp/km-041d.ini /etc/xrdp/km-040b.ini.

Layout ini files can also be generated if you manage to get the correct layout working manually first. You can try running setxkbmap -layout fi while logged on to the server locally (over xRDP you get the error XKB extension not present on :XX.X) When the layout is correct in the current session, run xrdp-genkeymap /etc/xrdp/km-040b.ini. The correct code for the file name (040b for finnish) can be found for example on this page.

After the correct layout file is added, logging out and back in with remote desktop should give the correct default key mappings automatically.

XTerm Autocomplete

If tab autocomplete doesn’t work in xterm in an xfce session over xrdp, then edit the following file:
~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml.

Change
<property name="<Super>Tab" type="string" value="switch_window_key"/>
to
<property name="<Super>Tab" type="empty"/>

Disable PC Speaker

By default the pc speaker is enabled, including error sounds from xterm (e.g. too many backspaces or no direct match from tab autocomplete). This can be really annoying because in an RDP session the beep seems to block all input and takes a long time to complete.

One solution is to disable the pc speaker: run xset -b in a terminal after login. To make the solution permanent, add [ -n "$DISPLAY"] && xset -b to ~/.bashrc (create the file if it does not exist).

References & Resources