Install Xfce VNC remote desktop on Ubuntu

XFCE is a lightweight Desktop Environment for Linux. XFCE + vnc allows you to set up a remote desktop on a VPS or dedicated server located in a remote data center or cloud. You can connect to remote desktop using a VNC client and work like it is a local computer, similar to Windows Remote Desktop (RDP).

Note: This post shows how to install Ubuntu, XFCE, and TightVNC. TightVNC has not been updated recently. Here is an instruction to use TigerVNC, which is actively maintained.

Ubuntu Remote VNC Server Setup with XFCE and TigerVNC

To install XFCE run

apt update
apt install -y xfce4 xfce4-goodies dbus-x11

You will be asked to select Default Display Manager. You can select any of the options.

Next install vncserver

apt install tightvncserver autocutsel

It is a bad idea to use root user for logging into the desktop. Create a normal user with sudo privileges to be used as desktop user.

useradd -m -s /bin/bash USERNAME

It will be good to make this user an admin, so the user can install software or update the system.

usermod -aG sudo USERNAME

Set a password for the user

passwd USERNAME

Now login as the user

su - USERNAME_HERE

Create a vnc password for this user.

vncpasswd

Create vnc startup file

vi ~/.vnc/xstartup

Add

#!/bin/bash

xrdb $HOME/.Xresources
autocutsel -fork
startxfce4 &

Make it executable

chmod 755 ~/.vnc/xstartup

Auto start VNC Server

To autostart vncserver on boot, you need to create a service file. You need to do the following as user root.

vi /etc/systemd/system/vncserver@.service

Add

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

[Service]
Type=forking
User=USERNAME
Group=USERNAME
WorkingDirectory=/home/USERNAME

PIDFile=/home/USERNAME/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

In the above, replace USERNAME with the actual user name you created above.

Enable the service with

systemctl enable vncserver@1

Start the VNC server

systemctl start vncserver@1

Now reboot the server. You should be able to connect to VNC server using SERVER_IP:1

Common Errors and Solutions

When starting vncserver, i get error

xfce4-session-CRITICAL **: 20:18:42.985: dbus-launch not found, the desktop will not work properly!

To fix it, install

apt install dbus-x11

OPTIONAL: Using RDP instead of VNC

If you want to use RDP (Windows Remote Desktop) to connect instead of VNC, install xrdp

apt install -y xrdp

Edit

vi /etc/xrdp/xrdp.ini

Set value of new_cursors to false.

new_cursors=false

Change to desktop user

su - USERNAME

Create file

vi ~/.xsession

Add following content

xfce4-session
export XDG_SESSION_DESKTOP=xubuntu
export XDG_DATA_DIRS=/usr/share/xfce4:/usr/local/share:/usr/share:/var/lib/snapd/USERNAME:/usr/share
export XDG_CONFIG_DIRS=/etc/xdg/xfce4:/etc/xdg:/etc/xdg

Enable and restart XRDP

systemctl enable xrdp
systemctl restart xrdp

See VNC Server

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *