Ubuntu – 20.04 XRDP KDE Plasma connect issue

kdexrdp

I am very new to Ubuntu and I just installed Ubuntu 20.04 LTS today and trying to setup XRDP so that I can remote -in into my Ubuntu machine from Windows
I executed the following steps:

sudo apt install xrdp 

I then tried all of these but only one at-a-time

sudo apt-get install kde-full
sudo apt-get install kde-desktop
sudo apt-get install kde-standard
sudo apt-get install kde-plasma-desktop

echo "startkde"  > ~/.xsession


sudo systemctl restart xrdp

when I try to connect, I get the login screen from xrdp and I select xorg and enter my username and password.
But then RDP session ends immediately

Can someone please help me set up XRDP and figure out what might be the issue? I can't stand gnome desktop. I would like to have KDE with XRDP.

Thanks

Best Answer

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:

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 YOUR_USER_NAME@71.44.33.22 -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 username@71.44.33.22 -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
Related Question