How to Install Desktop on Ubuntu Server
A brief on installing Xfce on Ubuntu Server, and accessing it remotely using Xrdp.
Hyperscalers like AWS, GCP or DigitalOcean make it really easy to spin up server instances for Ubuntu, Debian, Windows et al, but don't offer desktop environments for these distributions. Now I get it, desktops are a no-go in production but, on several occasions, I have had the need to spin up a Ubuntu or Windows desktop environment real quick for applications that require a desktop to function. Common desktop options in Linux are Xfce, Cinnamon, Gnome and KDE, but I'm generally a fan of Xfce for its minimal components. Today, I'll walk through the process of setting up Xfce on an Ubuntu server and accessing it remotely using Xrdp remote desktop application.
Create an Ubuntu Server Instance on DigitalOcean
I'm going to use DigitalOcean for this post - if you don't have an account, sign up here. If you sign up using my link, you’ll receive a $100, 60-day credit as soon as you add a valid payment method to your account.
Assuming you are familiar with droplet creation in DigitalOcean, I won't go into step-by-step detail. Basically, you need to choose a plan, an image (Ubuntu 20.04), the data center region, an authentication option (password for now, but SSH in a real environment) and the hostname.
Install Xfce and Xrdp on the Ubuntu Droplet
Once the droplet is ready, click on ...
next to the droplet and select Access droplet console
. Once you click Launch Droplet Console
, you will get remote root SSH access via a separate browser tab. Now run the following commands.
# Update the package metadata, install Xfce and Xrdp remote desktop app
apt-get update
apt-get install xubuntu-desktop
apt-get install xrdp
# This may take a while. Once completed, configure Xrdp to use Xfce by default in the startwm.sh file
sudo sed -i.bak '/fi/a #xrdp multiple users configuration \n xfce-session \n' /etc/xrdp/startwm.sh
# In the same file, comment the following lines
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
# And replace them with
startxfce4
# Xrdp uses the /etc/ssl/private/ssl-cert-snakeoil.key file that is only readable by members of the ssl-cert group; add xrdp to the group
adduser xrdp ssl-cert
# Restart the Xrdp service
service xrdp restart
You should now be able to connect to the server using Xrdp and any remote desktop client. On Windows, you can use the Remote Desktop Connection application. On Linux, you can use Remmina or Vinagre. Mac users can download the Microsoft Remote Desktop application from the Mac App Store.