20.04 XRDP KDE Plasma connect issue

This is how I configure XRDP for KDE-Plasma (works on my Ubuntu 20.04)

sudo apt install -y xrdp
sudo sed -e 's/^new_cursors=true/new_cursors=false/g' -i /etc/xrdp/xrdp.ini
sudo systemctl enable xrdp
sudo systemctl restart xrdp

Set session to plasma:

echo "/usr/bin/startplasma-x11" > ~/.xsession

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

If you have plasma installed, you can also login, and execute this on a console:

echo $XDG_SESSION_DESKTOP
echo $XDG_DATA_DIRS
echo $XDG_CONFIG_DIRS

to see if your values are the same.

Now to avoid the "authentication-required"-dialog:

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

Partial credits:

  • https://www.hiroom2.com/2018/05/07/ubuntu-1804-xrdp-kde-en/
  • https://www.hiroom2.com/2019/06/15/ubuntu-1904-xrdp-kde-en/
  • https://forum.kde.org/viewtopic.php?f=63&t=152803
  • https://bbs.archlinux.org/viewtopic.php?id=249974
  • Goooooogle

In case of error:

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

or just change the default-session-manager:

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

To allow root-access, go to /etc/pam.d/sddm and comment out this line:

auth    required        pam_succeed_if.so user != root quiet_success

2021 Update/Note:

Latest version of Windows 10 comes with an SSH client (and server).
So you can now natively tunnel your RDP-session over internet from a windows-box.
(I guess this is why we want xrdp in the first place)
So to do this, create a ssh-key:
ssh-keygen -t rsa -b 4096

With this command, ssh-keygen generates an RSA public-key in

C:\Users\<USERNAME>\.ssh\id_rsa.pub

along with id_rsa (private key)

Now append the content of id_rsa.pub (text-file) to

~/.ssh/authorized_keys 

in your linux box (this allows ssh-login for the user with home-directory ~ with the rsa-private-key and validates with the rsa-public-key - only copy the public key!)

Then your can open a ssh-connection with port-forwarding:

ssh [email protected] -C -L 1234:127.0.0.1:3389

(replace 71.44.33.22 with your ip/domain) Now you can connect with mstsc to 127.0.0.1:1234 which gets forwarded to 71.44.33.22:3389. 3389 is the default-xrdp-port.

Please validate that the ssh-login works in the first place, before you try to connect with mstsc.

Also, if you do this, please consider your rsa-keys as compromised, as Microsoft is a surveillance company. Don't do this for serious stuff. ! You have now been warned !
That said, your private Linux box is most-likely nothing that warrants this kind of seriousness.

Note on Syntax:

ssh  %user%@%servername-or-ip% -L %LocalPort%:127.0.0.1:%RemotePort%

-C for compression (argh, the speed, the speed).

You can also save the remote desktop session connection settings to a file, e.g. "C:\Program Files\Connections\Computername"

together with a connect.bat with content

start cmd /k ssh [email protected] -C -L 1234:127.0.0.1:3389
REM cd "C:\Program Files\Connections\Computername\"

REM START has a peculiarity involving double quotes 
REM around the first parameter. 
REM If the first parameter has double quotes 
REM it uses that as the optional TITLE for the new window.
start "" "C:\Program Files\Connections\Computername\computername.rdp"

Create a shortcut for the .bat file on the desktop with icons from C:\Windows\System32\mstsc.exe or C:\Windows\SysWOW64\mstsc.exe.

Best Linux program to connect to XRPD is remmina (IMHO).
To install:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:remmina-ppa-team/remmina-next
sudo apt-get update && sudo apt-get install remmina remmina-plugin-rdp libfreerdp-plugins-standard

Install Kubuntu 20.04 LTS

If you prefer KDE, it is better to install the Kubuntu desktop, rather than Ubuntu desktop plus the KDE desktop. This is because the Ubuntu desktop comes with Gnome and its default set of applications. When you install KDE desktop on top the Ubuntu desktop KDE brings in its own set of default applications. This creates unnecessary bloat and occasionally conflicts.

XRDP is hard to setup with Gnome Desktop

I don't know enough to tell you why this is, but I have learnt from experience that they don't work out of the box. Someone has written a script to get XRDP to work with the standard Ubuntu desktop. You may check it out if you decide to stay with the Ubuntu desktop and XRDP.

Warning: As with any script, read the script carefully and understand what exactly it does before deciding to use it on your computer.

Hope it helps