How to Install VNC on Ubuntu 16.04
Install VNC on Ubuntu 16.04
As you know, VNC is a protocol that allows sharing the desktop and controlled remotely over the internet. This simple guide helps you to install VNC on Ubuntu 16.04 machines.
Before installing the VNC server, let us install Xfce desktop.
$ sudo apt-get update
$ sudo apt-get install xfce4 xfce4-*
Install the VNC server using the following command.
$ sudo apt-get install vnc4server
VNC server listens on port 5900, but if you plan to setup port-offset in VNC; we can run a VNC service on a sub-port of the default port 5900.
For example, if we configure VNC for port 5, the desktop will be accessible on port 5905. To connect, you can use the standard format ipaddress:sub-port (192.168.2.109:5 or 192.168.2.109:5905)
$ sudo nano /etc/systemd/system/vncserver@:5.service
Replace
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=raj
PAMName=login
PIDFile=/home/raj/.vnc/%H%i.pid
#ExecStartPre=/usr/bin/vncserver -kill %i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1024x768 %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
Reload the systemctl daemon as root
$ sudo systemctl daemon-reload
Start VNC server as user “raj”
raj@server:~$ vncserver
Set the password.
You will require a password to access your desktops.
Password:
Verify:
xauth: file /home/raj/.Xauthority does not exist
New 'server.itzgeek.local:1 (raj)' desktop is server.itzgeek.local:1
Creating default startup script /home/raj/.vnc/xstartup
Starting applications specified in /home/raj/.vnc/xstartup
Log file is /home/raj/.vnc/server.itzgeek.local:1.log
Now, Edit the xstartup file to start Xfce desktop in VNC.
raj@server:~$ nano /home/raj/.vnc/xstartup
Delete all the existing entries and place the below lines into the file.
#!/bin/sh
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
startxfce4 &
Start the VNC service as root.
$ sudo systemctl start vncserver@:5.service
Enable it on system startup as root.
$ sudo systemctl enable vncserver@:5.service
Now use a VNC viewer to take the shared desktop.
ipaddress:5905 or ipaddress:5
That’s All.