To enable a desktop environment on your Ubuntu VPS, you’ll need to install a graphical user interface (GUI). Here’s a step-by-step guide to set it up:

Step 1: Update your system
Before starting, it’s a good practice to update your package list and upgrade your existing packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install a desktop environment
You have several options for desktop environments. Some popular choices for VPS are:
1. Install XFCE (lightweight desktop)
XFCE is a lightweight desktop environment that’s great for VPSs. To install it:
sudo apt install xfce4 xfce4-goodies -y
2. Install GNOME (full-featured desktop)
GNOME is the default desktop environment for Ubuntu, but it’s heavier than XFCE:
sudo apt install ubuntu-desktop -y
3. Install LXQt (another lightweight option)
LXQt is another lightweight option:
sudo apt install lxqt -y
Step 3: Install a display manager
A display manager handles user logins to the GUI. You can install one of the following:
For XFCE (and lightweight environments):
sudo apt install lightdm -y
For GNOME:
sudo apt install gdm3 -y
Step 4: Enable the graphical interface
Once the desktop environment and display manager are installed, enable the display manager to start on boot:
sudo systemctl enable lightdm # For XFCE
or
sudo systemctl enable gdm3 # For GNOME
Step 5: Start the graphical interface
Now, start the desktop environment:
sudo systemctl start lightdm # For XFCE
or
sudo systemctl start gdm3 # For GNOME
Step 6: Access your VPS via Remote Desktop
You will need to set up a remote desktop protocol (RDP) or VNC server to access the graphical environment. Here’s how to set up xrdp (RDP):
- Install xrdp:
sudo apt install xrdp -y
- Start and enable xrdp:
sudo systemctl enable xrdp sudo systemctl start xrdp
- Open port 3389 in your firewall to allow RDP access:
sudo ufw allow 3389/tcp
- Connect to your VPS via an RDP client (such as Remote Desktop on Windows or Remmina on Linux). Use your VPS IP address and login credentials.
Optional: Install VNC Server (alternative to RDP)
If you prefer VNC over RDP, you can install a VNC server like TigerVNC:
sudo apt install tigervnc-standalone-server tigervnc-viewer -y
After installation, set a password for VNC access:
vncpasswd
Then, start the VNC server:
vncserver
Finally, connect to your VPS using a VNC viewer, specifying your VPS IP and VNC port (usually :1
).
Let me know if you need further assistance or if you prefer a specific desktop environment!
Here’s a Bash script to install a desktop environment on your Ubuntu VPS. This script will:
- Update the system.
- Install the XFCE desktop environment (you can modify it for other environments if needed).
- Install and configure xrdp for remote access.
- Open port 3389 for RDP.
Bash Script: install_desktop.sh
#!/bin/bash
# Ensure the script is being run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system
echo "Updating system..."
sudo apt update && sudo apt upgrade -y
# Install XFCE desktop environment
echo "Installing XFCE desktop environment..."
sudo apt install xfce4 xfce4-goodies -y
# Install the display manager (lightdm for XFCE)
echo "Installing lightdm display manager..."
sudo apt install lightdm -y
# Enable lightdm to start at boot
echo "Enabling lightdm..."
sudo systemctl enable lightdm
# Start lightdm to initiate the desktop environment
echo "Starting lightdm..."
sudo systemctl start lightdm
# Install xrdp for remote desktop access
echo "Installing xrdp for RDP access..."
sudo apt install xrdp -y
# Enable and start xrdp
echo "Enabling and starting xrdp..."
sudo systemctl enable xrdp
sudo systemctl start xrdp
# Open firewall port 3389 for RDP access
echo "Opening firewall port 3389..."
sudo ufw allow 3389/tcp
# Provide instructions for remote connection
echo "Desktop environment and RDP setup complete!"
echo "You can now connect to your VPS using an RDP client (e.g., Remote Desktop on Windows, Remmina on Linux)."
echo "Use your VPS IP address and login credentials to access the GUI."
Instructions for Using the Script
- Create the script:
- On your VPS, create a new file:
nano install_desktop.sh
- Copy and paste the script above into the file, then save and exit (
Ctrl+X
,Y
,Enter
).
- On your VPS, create a new file:
- Make the script executable:
chmod +x install_desktop.sh
- Run the script:
sudo ./install_desktop.sh
The script will automatically install everything, configure the desktop environment, and set up RDP for remote access.
To enable remote desktop functionality and ensure it is available on startup for the desktop environment you set up, you’ll need to ensure xrdp is installed, configured correctly, and set to start automatically with the system.
Here’s how to modify your script and enable remote desktop access that starts automatically when the VPS boots:
Modifications to the Bash Script
You’ll want to ensure xrdp
starts automatically after installing and configuring the desktop environment, and that port 3389 (for RDP) is open in the firewall.
Here’s the modified script that takes care of everything:
Updated Bash Script: install_desktop.sh
#!/bin/bash
# Ensure the script is being run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system
echo "Updating system..."
sudo apt update && sudo apt upgrade -y
# Install XFCE desktop environment
echo "Installing XFCE desktop environment..."
sudo apt install xfce4 xfce4-goodies -y
# Install the display manager (lightdm for XFCE)
echo "Installing lightdm display manager..."
sudo apt install lightdm -y
# Enable lightdm to start at boot
echo "Enabling lightdm..."
sudo systemctl enable lightdm
# Start lightdm to initiate the desktop environment
echo "Starting lightdm..."
sudo systemctl start lightdm
# Install xrdp for remote desktop access
echo "Installing xrdp for RDP access..."
sudo apt install xrdp -y
# Enable and start xrdp
echo "Enabling and starting xrdp..."
sudo systemctl enable xrdp
sudo systemctl start xrdp
# Ensure xrdp runs in the correct session (XFCE)
echo "Configuring xrdp to use XFCE..."
echo "startxfce4" > ~/.xsession
# Restart xrdp service to apply changes
echo "Restarting xrdp service..."
sudo systemctl restart xrdp
# Open firewall port 3389 for RDP access
echo "Opening firewall port 3389..."
sudo ufw allow 3389/tcp
# Provide instructions for remote connection
echo "Remote desktop setup complete!"
echo "You can now connect to your VPS using an RDP client (e.g., Remote Desktop on Windows, Remmina on Linux)."
echo "Use your VPS IP address and login credentials to access the GUI."
Key Points to Note in the Updated Script:
- Installing and Enabling XRDP:
- The script installs xrdp (Remote Desktop Protocol server) to allow you to access the GUI via RDP.
- The script also ensures xrdp starts automatically by enabling and starting the
xrdp
service.
- Session Configuration for XRDP:
- The line
echo "startxfce4" > ~/.xsession
ensures that when you connect via RDP, xrdp will start the XFCE desktop environment.
- The line
- Firewall Port for RDP:
- The script opens port
3389
in the firewall, which is the default port for RDP.
- The script opens port
- Autostart and Restart:
- The script ensures that the
xrdp
service is restarted after configuring the session.
- The script ensures that the
Additional Steps (Manual Configuration if Needed)
- After running the script, you should be able to connect via RDP using a client like Remote Desktop (Windows) or Remmina (Linux).
- Use the VPS IP address and login credentials.
Making XRDP Automatically Start on Boot
systemctl enable xrdp
ensures that xrdp is enabled to start automatically when the server reboots, so you don’t have to manually start it every time.
When setting up a remote desktop environment with xrdp on Ubuntu, there are a few common issues that can arise. Below are some troubleshooting steps and fixes you might encounter:
1. Cannot Connect to Remote Desktop (RDP) – “Connection Refused”
This issue can be caused by several factors, including firewall settings, incorrect xrdp service status, or network issues.
Fix:
- Ensure xrdp is running: Make sure the
xrdp
service is active and running:sudo systemctl status xrdp
If it is not running, start it:sudo systemctl start xrdp
To enable xrdp to start on boot:sudo systemctl enable xrdp
- Open the RDP Port (3389): Ensure port 3389 is open in the firewall to allow RDP connections:
sudo ufw allow 3389/tcp
- Check Network Configuration: Ensure that the VPS is reachable from your local machine. Test the connection with
ping
:ping <your-vps-ip>
If it is not reachable, verify your network setup, including any cloud firewall or network restrictions.
2. Blank Screen or Black Screen After Login
If you successfully connect via RDP but get a black or blank screen after logging in, this is often due to a mismatch between the desktop environment and the session that xrdp
tries to start.
Fix:
- Set the correct session: Ensure the
~/.xsession
file exists and is properly configured. If you are using XFCE, the~/.xsession
file should contain:echo "startxfce4" > ~/.xsession
Then, restart thexrdp
service:sudo systemctl restart xrdp
- Check Logs: Review the
xrdp
logs for errors:sudo journalctl -u xrdp -xe
3. XRDP Login Fails – “Your session is being started” but gets stuck
This issue occurs when the session manager is not configured properly.
Fix:
- Ensure
.xsession
is set: As mentioned above, ensure the session is correctly defined in~/.xsession
. For XFCE, it should containstartxfce4
.echo "startxfce4" > ~/.xsession
- Use a Different Display Manager: If
lightdm
isn’t working correctly withxrdp
, you can try installing and using another display manager likegdm3
orsddm
:sudo apt install gdm3 sudo systemctl enable gdm3 sudo systemctl start gdm3
4. “Authentication Failed” After Logging In
If you get an “Authentication Failed” error even with the correct username and password, it could be due to incorrect user permissions or a misconfiguration in the PAM (Pluggable Authentication Modules).
Fix:
- Add the User to the
ssl-cert
Group:xrdp
uses thessl-cert
group for authentication. Add your user to this group:sudo adduser $USER ssl-cert
- Check the Password: Ensure the password you are using is correct. Sometimes the password or login might be case-sensitive, or special characters might cause problems.
5. Unable to Start Desktop Environment (e.g., GNOME or XFCE)
Sometimes, the desktop environment may not load properly, especially if there are conflicts between different desktop environments.
Fix:
- Reinstall the Desktop Environment: If XFCE is not working as expected, you can try reinstalling it:
sudo apt install --reinstall xfce4 xfce4-goodies
- Ensure the Correct Display Manager: If you’re using GNOME or another environment, ensure you have the correct display manager installed. For GNOME, you might need
gdm3
:sudo apt install gdm3 sudo systemctl enable gdm3 sudo systemctl start gdm3
- Check the
.xsession
Configuration: Double-check that the.xsession
file has the correct startup command for your desktop environment.
6. Audio or Clipboard Issues
By default, xrdp may not allow clipboard or audio sharing in the RDP session.
Fix for Clipboard Sharing:
- Install the
xrdp
package for clipboard support:sudo apt install xrdp-x11rdp
Fix for Audio:
- Audio over RDP requires additional configuration. You can try using
PulseAudio
for sound:sudo apt install pulseaudio
Then, configurexrdp
to use PulseAudio:sudo apt install pulseaudio-module-xrdp
7. No GUI (Graphical Interface) Available After Connecting
If you’re getting a blank screen or can’t access the desktop interface after a successful RDP connection, it may indicate issues with the graphical environment or desktop manager.
Fix:
- Reconfigure the Display Manager: Sometimes the
lightdm
orgdm3
display manager needs to be reset:sudo dpkg-reconfigure lightdm
Afterward, restartlightdm
orgdm3
:sudo systemctl restart lightdm
8. VPS Memory/CPU Constraints
If your VPS is under heavy load (memory or CPU), it may struggle to load the desktop environment.
Fix:
- Check System Resources: Use
htop
ortop
to check memory and CPU usage:htop
- Consider Upgrading VPS: If the issue is performance-related, consider upgrading your VPS to a plan with more resources (CPU, RAM).
Summary of Common Fixes:
- Ensure
xrdp
is running:sudo systemctl status xrdp
- Open port 3389 for RDP:
sudo ufw allow 3389/tcp
- Check
.xsession
configuration:echo "startxfce4" > ~/.xsession
- Restart services:
sudo systemctl restart xrdp
- Fix firewall/network issues: Check if the VPS is reachable and not behind a restrictive firewall.
- Check for desktop environment conflicts: Reinstall or configure the correct desktop environment.