This guide provides step-by-step instructions for setting up a graphical user interface (GUI) on a Linux virtual machine and accessing it remotely using Remote Desktop Protocol (RDP). This works for both Azure VMs and AWS EC2 instances.
Video Tutorial
For a visual walkthrough of this process, check out our YouTube tutorial:
🎬 Hate Command Line? Get a FULL GUI on Your Linux Cloud VM Instead!
Key Definitions
- GUI (Graphical User Interface): The visual way to interact with your computer using windows, icons, and menus instead of text commands.
- RDP (Remote Desktop Protocol): Microsoft's protocol that allows you to connect to and control a remote computer as if you were sitting in front of it.
- XRDP: An open-source implementation of the RDP protocol that allows RDP clients to connect to Linux machines.
- XFCE: A lightweight desktop environment for Linux that works well on virtual machines with limited resources.
- NSG/Security Group: Azure's Network Security Groups or AWS Security Groups act as virtual firewalls that control what network traffic is allowed to and from your VM.
Why Setup RDP on a Linux VM
Setting up RDP on your Linux VM offers several key advantages:
- Graphical Interface: Access Linux through a familiar desktop environment without using command line
- GUI Applications: Use software that requires a graphical interface (IDEs, browsers, office applications)
- Easier Administration: Some system management and configuration tools are more intuitive with a GUI
- File Management: Drag-and-drop file operations and visual file browsing
- Remote Work: Access your full Linux desktop from anywhere with an internet connection
Prerequisites
- A Linux VM on Azure or an EC2 instance on AWS (Ubuntu/Debian-based)
- SSH access to your VM
- Administrative (sudo) privileges on the VM
- Access to Azure Portal or AWS Console to configure security rules
Step 1: Install Desktop Environment and XRDP
- SSH into your Linux VM:
ssh username@your-vm-ip
- Update your system:
sudo apt update && sudo apt upgrade -y
- Install XFCE desktop environment (lightweight, works well for VMs):
sudo apt install -y xfce4 xfce4-goodies
- Install XRDP service:
sudo apt install -y xrdp
Step 2: Fix "Too Many Open Files" Issue
This is a common issue with XRDP on Linux VMs. Follow these steps to resolve it:
- Update system file descriptor limits:
sudo nano /etc/security/limits.conf
- Add these lines at the end of the file (before "# End of file"):
# Added file descriptor limits
* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535
- Create systemd limits configuration:
sudo mkdir -p /etc/systemd/system.conf.d/
sudo nano /etc/systemd/system.conf.d/limits.conf
- Add this content:
[Manager]
DefaultLimitNOFILE=65535
- Create XRDP-specific service override:
sudo mkdir -p /etc/systemd/system/xrdp.service.d/
sudo nano /etc/systemd/system/xrdp.service.d/override.conf
- Add this content:
[Service]
LimitNOFILE=65535
Step 3: Configure XRDP for XFCE
- Configure XRDP to use XFCE:
echo xfce4-session > ~/.xsession
- Modify XRDP configuration to change port and color depth:
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/max_bpp=16/g' /etc/xrdp/xrdp.ini
Note: We're changing to port 3390 to avoid potential conflicts. You can keep the default 3389 if desired.
- Reload systemd and restart services:
sudo systemctl daemon-reload
sudo reboot
Step 4: Configure Security Rules
For Azure VMs
- Log in to the Azure Portal
- Navigate to your VM
- Select "Networking" from the left sidebar
- Click "Add inbound port rule"
- Configure the rule:
- Protocol: TCP
- Destination port ranges: 3390 (or 3389 if you kept the default port)
- Priority: 1000 (or any available number)
- Name: AllowRDP3390
- Action: Allow
- Click "Add"
For AWS EC2 Instances
- Log in to the AWS Management Console
- Navigate to EC2 → Security Groups
- Select the security group associated with your instance
- Click "Edit inbound rules"
- Click "Add rule"
- Configure the rule:
- Type: Custom TCP
- Port range: 3390 (or 3389 if you kept the default port)
- Source: Your IP address or Custom (0.0.0.0/0 for anywhere - less secure)
- Description: RDP Access
- Click "Save rules"
Step 5: Connect Using Remote Desktop
-
On your Windows computer, open Remote Desktop Connection
- Press Windows+R, type
mstsc
and press Enter
- Press Windows+R, type
In the Computer field, enter:
your-vm-public-ip:3390
(Use :3389
if you kept the default port)
Click "Connect"
When prompted, enter your Linux VM username and password
You should now see the XFCE desktop environment
Troubleshooting
XRDP Won't Start or Shows Failed Status
Check the service status:
sudo systemctl status xrdp
If it shows failed, check the logs:
sudo journalctl -u xrdp
Black Screen After Connecting
- Verify your xsession file:
cat ~/.xsession
It should contain only: xfce4-session
- Try a different desktop environment:
sudo apt install -y lxde
echo lxsession > ~/.xsession
sudo systemctl restart xrdp
Connection Refused
If you get "connection refused" errors:
- Make sure XRDP is running:
sudo systemctl restart xrdp
sudo systemctl status xrdp
- Check if the port is listening:
sudo netstat -tuln | grep 3390
- Verify your NSG rule in Azure Portal
Poor Performance
- Reduce color depth further:
sudo sed -i 's/max_bpp=16/max_bpp=8/g' /etc/xrdp/xrdp.ini
sudo systemctl restart xrdp
- Consider using a lightweight desktop environment like LXDE:
sudo apt install -y lxde
echo lxsession > ~/.xsession
sudo systemctl restart xrdp
Additional Tips
- Install additional software as needed:
sudo apt install -y firefox gedit vlc
- To enable copy/paste between your local machine and the remote desktop:
sudo apt install -y xrdp-pulseaudio-installer
sudo xrdp-build-pulse-modules
- For automatic startup of applications, add them to:
~/.config/autostart/
- If you need to change back to the standard port:
sudo sed -i 's/port=3390/port=3389/g' /etc/xrdp/xrdp.ini
sudo systemctl restart xrdp
Security Considerations
- RDP traffic is not encrypted by default. Consider using a VPN or SSH tunneling for additional security
- Limit RDP access to specific IP addresses in your NSG rules
- Consider setting up multi-factor authentication for your Azure account
- Keep your system updated with the latest security patches
This guide should help you successfully set up and connect to a GUI environment on your Linux Azure VM. If you encounter any issues not covered in the troubleshooting section, refer to the Azure documentation or XRDP GitHub repository for more information.
Top comments (0)