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
1 |
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
1 |
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.
1 |
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.
1 |
usermod -aG sudo USERNAME |
Set a password for the user
1 |
passwd USERNAME |
Now login as the user
1 |
su - USERNAME_HERE |
Create a vnc password for this user.
1 |
vncpasswd |
Create vnc startup file
1 |
vi ~/.vnc/xstartup |
Add
1 2 3 4 5 |
#!/bin/bash xrdb $HOME/.Xresources autocutsel -fork startxfce4 & |
Make it executable
1 |
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.
1 |
vi /etc/systemd/system/vncserver@.service |
Add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[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
1 |
systemctl enable vncserver@1 |
Start the VNC server
1 |
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
1 |
apt install -y xrdp |
Edit
1 |
vi /etc/xrdp/xrdp.ini |
Set value of new_cursors to false.
1 |
new_cursors=false |
Change to desktop user
1 |
su - USERNAME |
Create file
1 |
vi ~/.xsession |
Add following content
1 2 3 4 |
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
1 2 |
systemctl enable xrdp systemctl restart xrdp |
See VNC Server