Repair Remote Desktop RDP on Ubuntu after installing VNC or XRDP
The Remote Desktop functionality in Ubuntu, based on the GNOME RDP protocol, presents itself as an efficient and quick option for those working remotely between a desktop computer and a laptop. However, it is common to encounter issues in this setup after installing additional servers like VNC or XRDP. This article will address the reasons behind these problems and provide a Bash script that allows for automatic system repairs in under a minute.
Common Issues After Installing VNC or XRDP
When adding additional remote desktop tools in Ubuntu, two main issues can arise:
Port 3389 Hijacking
Both the GNOME Remote Desktop service and the XRDP package use port 3389. When attempting to establish a connection from another device, it is possible that the wrong service responds, leading to rejected credentials.
Corrupted SSL/TLS Certificates
GNOME Remote Desktop requires encrypted connections via TLS. If the certificate files located in ~/.local/share/gnome-remote-desktop/ become corrupted or misconfigured, the server immediately terminates the connection for security reasons.
Read also
Solution: Automatic Repair Script
To simplify the process of diagnosing and repairing conflicts like these whenever they occur, a Bash script has been developed to perform the following actions:
- Frees up port 3389 by stopping conflicting services.
- Properly configures the firewall (ufw).
- Generates a suitable SSL/TLS certificate (2048-bit RSA) using OpenSSL.
- Registers the paths of the certificates and credentials in grdctl with absolute paths.
- Restarts the current user's daemon.
Script Code: repair_rdp_ubuntu.sh
To implement the repair, create a file on your desktop and paste the following code:
#!/bin/bash
# ==============================================================================
# Repair Script for Remote Desktop (GNOME RDP) - Ubuntu
# ==============================================================================
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${CYAN}====================================================${NC}"
echo -e "${CYAN} Automatic RDP Remote Desktop Repair Tool ${NC}"
echo -e "${CYAN}====================================================${NC}\n"
# 1. Execution Check (Do not run directly with sudo)
if [ "$EUID" -eq 0 ]; then
echo -e "${RED}[ERROR] Do not run this script directly with 'sudo'.${NC}"
echo -e "Run it with your normal user: ${YELLOW}./repair_rdp_ubuntu.sh${NC}"
exit 1
fi
CURRENT_USER=$USER
echo -e "${GREEN}[+] Detected User:${NC} $CURRENT_USER"
# 2. Prompt for remote access password
read -s -p "Enter the RDP connection PASSWORD: " RDP_PASS
echo ""
if [ -z "$RDP_PASS" ]; then
echo -e "${RED}[!] Password cannot be empty.${NC}"
exit 1
fi
echo -e "\n${YELLOW}[1/5] Freeing up port 3389 (disabling conflicting services)...${NC}"
sudo systemctl stop gnome-remote-desktop 2>/dev/null
sudo systemctl disable gnome-remote-desktop 2>/dev/null
sudo systemctl stop xrdp 2>/dev/null
sudo systemctl disable xrdp 2>/dev/null
echo -e "${YELLOW}[2/5] Configuring Firewall (UFW)...${NC}"
sudo ufw allow 3389/tcp > /dev/null
echo -e "${YELLOW}[3/5] Generating SSL/TLS certificate (RSA 2048)...${NC}"
CERT_DIR="$HOME/.local/share/gnome-remote-desktop"
rm -rf "$CERT_DIR"
mkdir -p "$CERT_DIR"
openssl req -new -x509 -days 365 -nodes -newkey rsa:2048 \
-out "$CERT_DIR/tls.crt" \
-keyout "$CERT_DIR/tls.key" \
-subj "/CN=$(hostname)" &>/dev/null
echo -e "${YELLOW}[4/5] Applying keys and credentials in grdctl...${NC}"
grdctl rdp set-tls-cert "$CERT_DIR/tls.crt"
grdctl rdp set-tls-key "$CERT_DIR/tls.key"
grdctl rdp set-credentials "$CURRENT_USER" "$RDP_PASS"
grdctl rdp enable
echo -e "${YELLOW}[5/5] Restarting user service...${NC}"
systemctl --user daemon-reload
systemctl --user restart gnome-remote-desktop
sleep 2
# Final Information
IP_ADDR=$(hostname -I | awk '{print $1}')
echo -e "\n${CYAN}====================================================${NC}"
echo -e "${GREEN} REPAIRS COMPLETED SUCCESSFULLY! ${NC}"
echo -e "${CYAN}====================================================${NC}"
echo -e "Configuration for Remmina / xfreerdp:"
echo -e " - ${YELLOW}Server/IP:${NC} $IP_ADDR"
echo -e " - ${YELLOW}Port:${NC} 3389"
echo -e " - ${YELLOW}User:${NC} $CURRENT_USER"
echo -e " - ${YELLOW}Protocol:${NC} RDP"
echo -e "${CYAN}====================================================${NC}\n"How to Use the Script
- Save the above code to a file named repair_rdp_ubuntu.sh.
- Grant execution permissions from the terminal with the following command:
chmod +x repair_rdp_ubuntu.sh
- Execute it as a normal user using:
./repair_rdp_ubuntu.sh
The script will prompt for the password for remote access and will take care of restoring Remote Desktop functionality.
Read also
How to Test the Connection from Your Laptop
After running the script on your desktop computer, open the terminal on your laptop to conduct a quick test using xfreerdp or set up a profile in Remmina by selecting the RDP protocol:
xfreerdp /v:192.168.X.X /u:your_username /p:your_password /cert:ignore
Make sure to replace 192.168.X.X with the local IP address of your desktop computer.
With these steps, full control over Remote Desktop in Ubuntu will be restored without the need to restart the system or reinstall the graphical interface.
For more tutorials and solutions on related topics, feel free to keep reading the blog. Until next time!



