Complete Guide to Ubuntu/Debian VPS Server Setup with Remote Desktop

Complete Ubuntu/Debian VPS Server Setup Guide with Remote Desktop Access

Introduction

This comprehensive guide will walk you through setting up a new Ubuntu or Debian VPS server, from initial security configuration to enabling remote desktop access via RDP or VNC.

Prerequisites

  • A VPS with Ubuntu 20.04/22.04 or Debian 10/11 installed
  • SSH access to the server as root user
  • An SSH client (PuTTY for Windows or terminal for Linux/Mac)
  • Basic familiarity with Linux command line

Step 1: Initial Server Access

Connect to your VPS via SSH:

ssh root@your_server_ip

Enter your password when prompted (or use SSH key if configured).

Step 2: System Update

Before proceeding, update your system packages:

apt update && apt upgrade -y

This command updates the package list and installs all available updates.

Note: On some systems, you might need to use apt-get instead of apt.

Step 3: Create a New User (Recommended)

For security reasons, it’s best not to use the root account for daily operations:

adduser yourusername

Add the user to the sudo group to grant administrative privileges:

usermod -aG sudo yourusername

To switch to the new user:

su – yourusername

Step 4: Basic Security Setup

Firewall Configuration

Ubuntu/Debian comes with ufw (Uncomplicated Firewall):

apt install ufw -y ufw allow OpenSSH ufw enable

Check firewall status:

ufw status

SSH Hardening

Edit the SSH configuration:

sudo nano /etc/ssh/sshd_config

Modify or add these lines:

Port 2222                 # Change from default port 22
PermitRootLogin no        # Disable root login
PasswordAuthentication no # Require SSH key authentication
MaxAuthTries 3            # Limit authentication attempts
ClientAliveInterval 300   # Disconnect idle sessions
ClientAliveCountMax 2

Restart SSH service:

sudo systemctl restart sshd

Warning: Ensure you’ve set up SSH key authentication before disabling password login, or you may get locked out!

Step 5: Install Desktop Environment

Choose one of these desktop environments:

Option 1: XFCE (Lightweight – Recommended)

sudo apt install xfce4 xfce4-goodies -y

Option 2: GNOME (Full-featured but heavier)

sudo apt install ubuntu-desktop -y # For Ubuntu sudo apt install gnome-core -y # For Debian

Option 3: MATE (Balance between features and performance)

sudo apt install ubuntu-mate-core -y

Step 6: Set Up Remote Access

Method 1: RDP (Recommended)

Install xrdp for Remote Desktop Protocol access:

sudo apt install xrdp -y

Configure xrdp to use your desktop environment:

echo “xfce4-session” > ~/.xsession # For XFCE # OR echo “gnome-session” > ~/.xsession # For GNOME

Allow RDP port in firewall:

sudo ufw allow 3389/tcp

Start and enable xrdp service:

sudo systemctl enable xrdp sudo systemctl restart xrdp

Method 2: VNC (Alternative)

Install TightVNC server:

sudo apt install tightvncserver -y

Set up VNC server (run as regular user, not root):

vncserver

You’ll be prompted to set a password (minimum 6 characters).

Configure the startup script:

nano ~/.vnc/xstartup

Add these lines (for XFCE):

#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &

Or for GNOME:

#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
gnome-session &

Make the script executable:

chmod +x ~/.vnc/xstartup

Allow VNC port in firewall:

sudo ufw allow 5901/tcp

Start VNC server with specific resolution:

vncserver -geometry 1280×720

Step 7: Connect from Remote Computer

For RDP Connections

Windows:

  1. Open “Remote Desktop Connection” (mstsc.exe)
  2. Enter your server’s IP address
  3. When prompted, enter your username and password

Linux/Mac:

  1. Install Remmina (Linux) or Microsoft Remote Desktop (Mac)
  2. Create new connection with server IP and credentials

For VNC Connections

  1. Install a VNC viewer (TightVNC, RealVNC, or TigerVNC)
  2. Connect to your_server_ip:1 (port 5901)
  3. Enter the VNC password you set earlier

Step 8: Additional Configurations (Optional)

Auto-start VNC on Boot

Create a systemd service for VNC:

sudo nano /etc/systemd/system/vncserver@.service

Add this content (replace ‘yourusername’ with your actual user):

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=yourusername
PAMName=login
PIDFile=/home/yourusername/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x720 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload sudo systemctl enable vncserver@1.service sudo systemctl start vncserver@1.service

Improve RDP Performance

Install additional components for better RDP performance:

sudo apt install xorgxrdp -y

Edit xrdp configuration:

sudo nano /etc/xrdp/xrdp.ini

Under [xrdp1] section, modify:

name=sesman-Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1

Restart xrdp:

sudo systemctl restart xrdp

Troubleshooting Common Issues

Black Screen on Remote Connection

Solution: Ensure correct desktop environment is specified in:

  • For RDP: ~/.xsession
  • For VNC: ~/.vnc/xstartup

Connection Refused

Check services are running:

sudo systemctl status xrdp # For RDP sudo systemctl status vncserver@1 # For VNC

Verify firewall allows the ports:

sudo ufw status

Poor Performance

Try these optimizations:

  1. Reduce color depth: vncserver -depth 16
  2. Use smaller resolution: vncserver -geometry 1024x768
  3. For RDP, edit /etc/xrdp/xrdp.ini and set max_bpp=16

Important Security Considerations

  • Change default ports: Consider changing RDP/VNC ports from defaults
  • Use VPN: For production servers, access RDP/VNC only through VPN
  • Fail2Ban: Install to prevent brute force attacks:
    sudo apt install fail2ban -y
  • Regular updates: Keep your system updated with:
    sudo apt update && sudo apt upgrade -y

Conclusion

Your Ubuntu/Debian VPS is now set up with a graphical desktop environment accessible remotely via RDP or VNC. Remember to:

  • Maintain regular system updates
  • Use strong passwords or SSH keys
  • Consider additional security measures like VPN for remote access
  • Monitor server resources as GUI environments consume more memory

For production environments, consider using SSH tunneling for RDP/VNC connections instead of exposing these services directly to the internet.

Scroll to Top