Linux server distros don’t usually ship with a graphical user interface, instead favoring access over SSH using a terminal. But, some applications are easier to use in a window, and even headless servers can run desktop environments over RDP.
Why Install a GUI?
First off, there are plenty of reasons not to install a GUI. More code and packages mean more updating, downtime, and potential security vulnerabilities. Even lightweight desktop environments can consume a lot of resources, especially on a small server without much RAM. In production, it’s often not necessary, because command line access is almost always enough to set up whatever application you’re running (at least on Linux).
However, there are a few scenarios where it makes sense. Some applications are a lot more manageable with a GUI. VirtualBox, for example, is used to create virtual machines to run different operating systems in a contained environment. It’s primarily a GUI-based application, and is much easier to manage when you have a display to work with. While it’s entirely possible to work with it from the command line, it’s admittedly a bit clunky, and you’ll be stuck reading documentation and looking up guides on which commands to use before you can remember the most important ones.
While we still don’t recommend using a desktop environment on a user-facing server, it can be nice to set up on a home server or other non-essential machine. After all, Windows servers heavily rely on GU-based applications accessed over RDP. While Linux favors the command line, it’s nice to have options.
Installing a Desktop Environment
There are two moving parts required to get a GUI working on a remote Linux server. The first is the desktop environment, which everything related to your visual perception of the OS, window management most importantly. The second is the Remote Desktop Protocol (RDP) server; because you probably don’t have physical access to your server, you won’t have a display port to jack into. Even if you do, having remote administration access is ideal, as it allows you to work from anywhere using your personal computer.
As far as desktop environments go, you have a lot of options, considering Linux is also used as a desktop operating system. If you’re just looking for a lightweight desktop environment, we would recommend XFCE. It’s fast, and doesn’t require a lot of resources to run. Alternatively, if you’re looking for a nicer experience, you can try KDE, which is more suited to daily use.
apt-get update to update your package lists before installation:
sudo apt update
Next, if you want to install XFCE, run the following command:
sudo apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils
This will likely install some related packages, so installation may take some time.
If you’d rather use KDE, you can install the full package with:
sudo apt install kde-full
To say this will install more packages than XFCE would be an understatement.
Needless to say, the installation for KDE will take some time. If you’re a fan of KDE, and want a more lightweight version, you can try
kde-plasma-desktop instead of
XRDP is an RDP server that will handle remote connections to the desktop environment. Install it from apt:
sudo apt-get install xrdp
It should start automatically after install. You can check that it’s loaded and active with:
sudo systemctl status xrdp
You’ll want to add this to the
ssl-cert group so that it has access to secure the connection.
sudo adduser xrdp ssl-cert
Next, you’ll have to configure XRDP so that it will start your desktop environment. Open up
~/.xsession, and give it the command to start your DE. For XFCE, that would be:
Pretty simple. For KDE though, you’ll want to also open up
~/.xsessionrc and paste in the following:
export XDG_SESSION_DESKTOP=KDE export XDG_DATA_DIRS=/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop export XDG_CONFIG_DIRS=/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings
This sets the data and config directories that the DE needs to function.
Once everything is configured, restart the XRDP service to apply the changes:
sudo systemctl restart xrdp
The default port for RDP is 3389. You might need to allow this in your firewall in order to access the server. The DE may require some additional setup before being fully secure, so you’ll probably want to whitelist access to only your personal IP address:
sudo ufw allow from 192.168.1.1 to any port 3389
Simply put in the address of your server, and enter in your username and password for the account you wish to use to connect. RDP doesn’t have a built in way to use SSH keys rather than passwords, though you can set up an SSH tunnel to achieve the same effect.