How to enable RDP for Ubuntu 22.04 Desktop

Last time, I enable RDP connection for Ubuntu Desktop. Everything works fine except browser. Then, my teacher asked dealer technicians to install new system for this server. The reason is that Ubuntu Server 22.04 cannot mount external disk automatically due to unknown reasons. This time I need to install XRDP for new system, however, things became different compared to last time. Some configure need to modify. So I decide to write this post to record my process for reference in case of next time I need to do the same thing.

Environment

Ubuntu 22.04.4 LTS Desktop

Basic installation

Log into your server as root.

1
2
3
4
5
apt update
apt upgrade
apt install xrdp lightdm
systemctl enable xrdp
vim /etc/xrdp/startwm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# xrdp X session start script (c) 2015, 2017, 2021 mirabilos
# published under The MirOS Licence

# Rely on /etc/pam.d/xrdp-sesman using pam_env to load both
# /etc/environment and /etc/default/locale to initialise the
# locale and the user environment properly.


if test -r /etc/profile; then
. /etc/profile
fi

export $(dbus-launch)

test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession

#unset DBUS_SESSION_BUS_ADDRESS
#unset XDG_RUNTIME_DIR

1
2
su - user_you_want_to_use_when_login_in_RDP
vim .xsessionrc
1
2
3
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
1
vim .xsession
1
gnome-session
1
2
exit
service restart xrdp

Refinement

Refine for network stream

1
vim /etc/xrdp/xrdp.ini
1
2
tcp_send_buffer_bytes=4194304
tcp_recv_buffer_bytes=6291456
1
vim /etc/sysctl.conf
1
2
net.core.rmem_max = 12582912
net.core.wmem_max = 8388608
1
2
sudo sysctl -p
service xrdp restart

Avoid entering passwords multiple time after login

Screenshot 2024-07-26 at 17.56.50

In order to avoid situation shown above, we need to edit configuration.

1
vim /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla
1
2
3
4
5
6
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
1
service xrdp restart

Reference

  1. https://developer.aliyun.com/article/762186
  2. https://www.cnblogs.com/bruce1992/p/16535833.html
  3. https://blog.csdn.net/Fatmear/article/details/122037566
  4. https://zhuanlan.zhihu.com/p/519648451
  5. https://cloud.tencent.com/developer/article/2355160
  6. https://askubuntu.com/questions/1404245/remote-desktop-from-windows-onto-ubuntu-22-04-takes-me-to-a-xrdp-login-then-a-bl/1404412#1404412?newreg=d7c4bd7dd87443868825cd6cdb6f403d
  7. https://blog.csdn.net/wu_weijie/article/details/108481456