Linux remote desktop with xrdp and Kubuntu

Linux remote desktop with xrdp and Kubuntu
Page content

Remote desktop on linux is sometimes a bit of a pain. With xdrp there is a solution, that works pretty well, although it utilises a Microsoft Protocol and sometimes does not work out of the box - the configuration is tricky. Here is how to set up with Kubuntu.

Introduction

The Remote Desktop Protocol (RDP) is a proprietary protocol to connect a user interface over network. On Windows systems, this protocol can be used out of the box while on Linux you have to install an extra service. The most popular one is xrdp.

Enable xrdp on Kubuntu >= 19.04

Instead of going too much into detail, here is a list of commands to execute (also usable as script). After these you should have your xrdp up and running on Kubuntu:


# install xrdp service
sudo apt install -y xrdp

## fix black cursor bug
sudo sed -e 's/^new_cursors=true/new_cursors=false/g' -i /etc/xrdp/xrdp.ini

# enable and start xrdp service
sudo systemctl enable xrdp
sudo systemctl restart xrdp

# Set session to plasma
echo "/usr/bin/startplasma-x11" > ~/.xsession

# store variables for .xsessionrc
export D=/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export C=/etc/xdg/xdg-plasma:/etc/xdg
export C=${C}:/usr/share/kubuntu-default-settings/kf5-settings


cat <<EOF > ~/.xsessionrc
export XDG_SESSION_DESKTOP=KDE
export XDG_DATA_DIRS=${D}
export XDG_CONFIG_DIRS=${C}
EOF

# fix "authentication required" bug
cat <<EOF | \
  sudo tee /etc/polkit-1/localauthority/50-local.d/xrdp-NetworkManager.pkla
[Netowrkmanager]
Identity=unix-group:sudo
Action=org.freedesktop.NetworkManager.network-control
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF

cat <<EOF | \
  sudo tee /etc/polkit-1/localauthority/50-local.d/xrdp-packagekit.pkla
[Netowrkmanager]
Identity=unix-group:sudo
Action=org.freedesktop.packagekit.system-sources-refresh
ResultAny=yes
ResultInactive=auth_admin
ResultActive=yes
EOF
sudo systemctl restart polkit

Client tools and testing

The above commands should work, but you need a client tool to perform the real check. Fortunately, there is software for the most common operating systems:

  • Windows
    • mstsc - default microsoft tool, included in Windows
    • mRemoteNG - more sophisticated with connection management, but 3rd party
  • MacOS
  • Linux
    • Remmina - via package manager or instructions on website
  • Web-App / Alternatives

Troubleshooting

If it does not work, you might change the default session manager:

sudo update-alternatives --config x-session-manager

Maybe the values for some variables are not the same. To compare these on plasma, login and run:

echo $XDG_SESSION_DESKTOP
echo $XDG_DATA_DIRS
echo $XDG_CONFIG_DIRS

If the values are not the same to the ones used in the script, try to fix them. Otherwise, you should take a look at the logs:

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

What else should I know?

While most of the time, this solution works like a charm, there are some things you should know about.

Limitations

  • Remote unlocking of encrypted drives is not possible without extra tools (like ssh)
  • Remote login and local login are not possible at the same time (often, after a remote login local logins don’t work anymore)
    • There are workarounds, but they also come with limitations
  • The connection speed is not as good as on native Windows systems

Root access

For root-access, open /etc/pam.d/sddm and comment out the line:

#auth   required   pam_succeed_if.so user != root quiet_success

What about Gnome and others?

Well, xrdp also works on Gnome and others. For Gnome and further research I found this pretty helpful

Credits

Thanks to WitchCraft and c-nergy

Andreas Fuhrich avatar
About Andreas Fuhrich
I’m a professional software developer and tech enthusiast from Germany. On this website I share my personal notes and side project details. If you like it, you could support me on github - if not, feel free to file an issue :-)