How to enable remote desktop for Ubuntu Desktop

In last post, I installed Ubuntu Desktop based on soft raid 1. Due to the need of remote maintenance for scientific software, I need a GUI environment. In this post, let’s learn how to do this.

VNC configuration (Not recommended)

When I want to deploy, VNC first comes into my mind, as I used it many times with my Raspberry Pi. However, it does not suit well with Ubuntu. Ubuntu default desktop(gnome) use Wayland as display server, which is not compatible with VNC. I have tried to use VNC to connect with gnome, it showed a grey screen and a black folk as mouse cursor. It cannot use at all. So we need to install new Desktop GUI.

1
2
3
4
sudo apt install xfce4 xfce4-goodies # install xfce4 as Desktop GUI
sudo apt install tigervnc-standalone-server tigervnc-common # install tigervnc. Do not install tightvncserver, which is not compatible with Ubuntu in my experience.
cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
vim ~/.vnc/xstartup
1
2
3
4
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
1
2
chmod +x xstartup
vncserver # you need to set password if it is first time use

Then you can use VNC client to connect to your server. The default ip port is 5901 if your socket is :1, 5902 for :2 and so on.

Some useful commands:

1
2
3
vncserver -list # show all vncserver sockets
vncserver -kill :1 # kill specific vncserver sockets
vncserver -localhost no # allow connection from remote ip

XRDP configuration (Recommended)

1
2
3
4
5
sudo apt update
sudo apt install xfce4 xfce4-goodies -y
sudo apt install xrdp -y
sudo systemctl status xrdp # it should be active, if it is inactive, you need to run command: sudo systemctl start xrdp
sudo vim ~/.xsession
1
gnome-session
1
sudo vim /etc/xrdp/startwm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/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

# add the following two line to solve the black screen issue. The black screen is due to the gnome will prevent a new windows in default.
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR

test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
1
vim ~/.xsessionrc # to make the desktop environment the same as the local monitor shows
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
sudo systemctl restart xrdp.service

Then you can use your RDP client to connect to your Ubuntu Desktop.

Issue not solved

However, I still cannot open Firefox Browser in RDP at the end.

Screenshot 2024-03-08 at 11.48.36

I also tried chromium, also failed. Hope there is a solution.

1
2
sudo apt update
sudo apt install chromium-browser

Screenshot 2024-03-08 at 12.00.49

Reference

  1. https://juejin.cn/s/vncserver%20grey%20screen%20ubuntu%2020.04
  2. https://www.myfreax.com/how-to-install-and-configure-vnc-on-ubuntu-22-04/
  3. https://www.zhuji66.com/how-to-connect-ubuntu-use-rdp-on-windows/
  4. https://zhuanlan.zhihu.com/p/519648451