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:
Enter your password when prompted (or use SSH key if configured).
Step 2: System Update
Before proceeding, update your system packages:
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:
Add the user to the sudo group to grant administrative privileges:
To switch to the new user:
Step 4: Basic Security Setup
Firewall Configuration
Ubuntu/Debian comes with ufw (Uncomplicated Firewall):
Check firewall status:
SSH Hardening
Edit the SSH configuration:
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:
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)
Option 2: GNOME (Full-featured but heavier)
Option 3: MATE (Balance between features and performance)
Step 6: Set Up Remote Access
Method 1: RDP (Recommended)
Install xrdp for Remote Desktop Protocol access:
Configure xrdp to use your desktop environment:
Allow RDP port in firewall:
Start and enable xrdp service:
Method 2: VNC (Alternative)
Install TightVNC server:
Set up VNC server (run as regular user, not root):
You’ll be prompted to set a password (minimum 6 characters).
Configure the startup script:
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:
Allow VNC port in firewall:
Start VNC server with specific resolution:
Step 7: Connect from Remote Computer
For RDP Connections
Windows:
- Open “Remote Desktop Connection” (mstsc.exe)
- Enter your server’s IP address
- When prompted, enter your username and password
Linux/Mac:
- Install Remmina (Linux) or Microsoft Remote Desktop (Mac)
- Create new connection with server IP and credentials
For VNC Connections
- Install a VNC viewer (TightVNC, RealVNC, or TigerVNC)
- Connect to
your_server_ip:1
(port 5901) - Enter the VNC password you set earlier
Step 8: Additional Configurations (Optional)
Auto-start VNC on Boot
Create a systemd service for VNC:
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:
Improve RDP Performance
Install additional components for better RDP performance:
Edit xrdp configuration:
Under [xrdp1] section, modify:
name=sesman-Xvnc lib=libvnc.so username=ask password=ask ip=127.0.0.1 port=-1
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:
Verify firewall allows the ports:
Poor Performance
Try these optimizations:
- Reduce color depth:
vncserver -depth 16
- Use smaller resolution:
vncserver -geometry 1024x768
- For RDP, edit
/etc/xrdp/xrdp.ini
and setmax_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.