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).
To install XFCE run
apt install -y xfce4 xfce4-goodies
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/[email protected]
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 > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i 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
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