If you’d like to access your Linux desktop over the network from anywhere in the world, or just want to share your computer’s resources on the LAN by giving all users accounts on your computer, you can set up a remote desktop server. It is quite easy to do so, and the best part is that it is compatible with the remote desktop client on Windows too, thanks to the software called XRDP which talks Remote Desktop Protocol (RDP).

Are you surprised that a blog that usually used to talk about Gentoo, is now posting about Ubuntu? Well, I made switch on my personal machine to Linux Mint Cinnamon because I was bored with Gentoo. I have nothing against Gentoo, and I still love it. It’s the perfect distribution if you want to customize your OS to the core.

If you are going with Linux Mint, I’d highly recommend the MATE desktop. MATE is basically a fork of the original GNOME 2 project. GNOME 3 / Cinnamon / Unity won’t work with XRDP because they rely on 3D graphics which is not possible (yet) on X11RDP or Xvnc (correct me if I’m wrong). You could also go with the other desktop environments like XFCE or LXDE if you prefer. Even KDE works fine in the remote desktop environment because it does not solely rely on 3D graphics.

We’ll be building the latest XRDP version from source as the package in Ubuntu repositories is old, and plus, we need X11rdp which is not available there. In XRDP, there are two ways to get the display – one using X11rdp and other using Xvnc, TightVNC or X11VNC. Although it is very easy to run XRDP with *VNC, I use X11rdp for performance reasons, and for XKB (X Keyboard Extension) which is not supported by the VNC displays – and this sometimes tends to break the numpad functionality on the keyboard, especially with browsers like Firefox and Chrome.

How XRDP works

I don’t know the internal details of protocol or the software, but I know the flow. The flow is:

  • User connects to XRDP Server using an RDP client
  • XRDP presents a authentication dialog box which also contains a dropdown for selecting session module
  • User enters the details
  • XRDP sends this information to Session Manager which authenticates the user against PAM
  • If authentication is successful, a new X11rdp instance is spawned according to the display information provided by the client and /etc/xrdp/startwm.sh is run which starts the desktop environment.

In the traditional desktop case, we typically have one X11 server which is started by the login manager like GDM or similar and from there we login. In case of XRDP, the X11 server here is X11rdp (or Xvnc, if you use that mode) and then the session manager of the desktop environment connects to it.

Preparing the environment

The XRDP source code seems to have moved to GitHub from it’s original location at xrdp.org. Download the latest release from there. We need to install some stuff that is required to build xrdp. Firstly, check that you have the source repositories enabled for aptitude in /etc/sources.list or /etc/sources.list.d. Install the required stuff:

Extract the XRDP archive you downloaded, or if you cloned the git repository, get into it and run:

Next, in the same directory, you will find a subdirectory named xorg. Inside that there is a folder X11R7.6 (the version number might change in future). cd into it and as root (or sudo), ./buildx.sh /opt/X11rdp. This will build the X11rdp binary and install it in /opt/X11rdp. Once that is installed, create a symlink to X11rdp: ln -s /opt/X11rdp/bin/X11rdp /usr/bin/X11rdp so that XRDP can find the X11rdp binary.

Generate the RSA keys for XRDP

Configuration tweaks in /etc/xrdp

XRDP will install it’s default configuration in /etc/xrdp. We need to edit two files, the file named xrdp.ini and sesman.ini. In xrdp.ini, change max_bpp to 24 (the default value is 32) and set new_cursors=no. It seems X11rdp does not support 32 bit color, so I set the maximum bits per pixel to 24. New cursors cause ugly-looking cursors so they need to be disabled. In sesman.ini, scroll down to the section which says X11rdp]. At the end of the section, add a line: param6=-once. The final section should be like this:

We added -once to the parameter list so that X11rdp will terminate once the desktop session ends. Otherwise X11rdp keeps running and consuming resources displaying your desktop wallpaper :P.

That’s it, now if you run /etc/xrdp/xrdp.sh start, you should be able to login to the remote desktop server and see your desktop. If you don’t check the logs.
If you have multiple desktop environments installed, edit /etc/xrdp/startwm.sh and export the variable STARTUP before wm_start function to call the session manager of your desktop environment, such as mate-session, xfce4-session, startkde, etc.

CPU / IO hogging bug in mate-settings-daemon
Note: Skip this section if you are running Linux Mint 17.2 or non MATE desktop environment

If you are using MATE desktop, there is a bug in mate-settings-daemon which causes excessive CPU and IO usage when you use the numpad and it kills your machine. To avoid this, you need to apply a patch to the source code and install mate-settings-daemon-pulse package. The patch can be found in my comment on a GitHub issue.

Note that the above procedure is valid only for version 1.8.2 which is the current stable version that is there in Linux Mint 17.1. Before building the source of mate-settings-daemon, check the status of the issue, the current version that you are using and apply the patch if required.

/run/user/0 permission denied bug in pam_systemd

SystemD has a bug which does not create the /run/user/* directories with proper permissions which causes errors when starting up the desktop environment or it does not start at all. So until that is fixed, we have to fix this using an ugly hack. Add these 3 lines in the pre_start function of /etc/xrdp/startwm.sh at the end before the return 0:

Happy RDPing!

Advertisements