Install Xfce VNC remote desktop on Ubuntu
XFCE is a light weight desktop for Linux. XFCE + vnc allow you to setup remote desktop on a VPS or dedicated server located on a data center or cloud. You can connect to remote desktop using VNC client and work like it is local computer.
To instal XFCE run
1 |
apt install -y xfce4 xfce4-goodies |
Next install vncserver
1 |
apt install -y vnc4server |
This installs package tigervnc-standalone-server.
It is bad idea to use root user for logging into desktop. Create a normal user to run desktop.
1 |
useradd -m -s /bin/bash USERNAME_HERE |
It will be good to make this user an admin, so user can install software or update system.
1 |
usermod -aG sudo USERNAME_HERE |
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 6 7 |
#!/bin/bash xrdb $HOME/.Xresources /usr/bin/vncconfig -nowin -display :1 & startxfce4 & |
Make it executable
1 |
chmod 755 ~/.vnc/xstartup |
Now exit the user with “exit” command. You should be user “root” now.
1 |
vi /etc/vnc.conf |
Uncomment line
1 |
$localhost = "no"; |
If not, VNC only listen on localhost IP 127.0.0.1
Auto start VNC Server
To autostart vncserver on boot, you need to create a service file.
1 |
vi /etc/systemd/system/vncserver@.service |
Add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[Unit] Description=VNC server startup script After=syslog.target network.target [Service] Type=forking User=USERNAME_HERE ExecStartPre=/usr/bin/vncserver -kill :%i &> /dev/null ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i PIDFile=/home/USERNAME_HERE/.vnc/%H:%i.pid ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target |
Enable the service with
1 |
systemctl enable vncserver@1 |
You can start/stop vncserver with
1 2 |
systemctl stop vncserver@1 systemctl start vncserver@1 |
Now reboot the server. You should be able to connect to VNC server using SERVER_IP:1
Auto start using rc.local
Enable rc.local with
1 |
systemctl enable rc-local |
Create /etc/rc.local file with following content
1 2 3 4 5 6 |
#!/bin/bash runuser -u USERNAME_HERE -- /usr/bin/vncserver -kill :1 &> /dev/null runuser -u USERNAME_HERE -- /usr/bin/vncserver -depth 24 -localhost no -geometry 1680x1050 :1 echo "rc.local started" >> /root/rc-local.txt |
Make /etc/rc.local executable
1 |
chmod 755 /etc/rc.local |
On reboot /etc/rc.local will be executed.
See VNC Server