Install and Configure a VNC in Ubuntu
To install TigerVNC server and other associated packages in Ubuntu, run the following command.
$ sudo apt install tigervnc-standalone-server tigervnc-common tigervnc-xorg-extension tigervnc-viewer
Now start the VNC server by running the vncserver command as a normal user. This action will create the initial configuration stored in the $HOME/.vnc
directory and it will also prompt you to set up a login password.
Enter a password (which must be at least six characters length) and confirm/verify it. Then set a view-only password if you wish, as follows.
$ vncserver
$ ls -l ~/.vnc
Next, we need to configure the DE to work with the VNC server. So, stop the *VNC* server using the following command, in order to perform some configurations.
$ vncserver -kill :1
To configure GNOME or whatever desktop you have installed, create a file called xstartup under the configurations directory using your favorite text editor.
$ vi ~/.vnc/xstartup
Add the following lines in the file. These commands will be automatically executed whenever you start or restart the TigerVNC server. Note that the commands may vary depending on the DE you installed.
#!/bin/sh
exec /etc/vnc/xstartup
xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &
Save the file and set the appropriate permission on the file so it can be executed.
$ chmod 700 ~/.vnc/xstartup
Next, start the VNC server by running the following command as a normal user. Set your own values for the display geometry. In addition, use the -localhost
flag to allow connections from the localhost only and by analogy, only from users authenticated on the server.
In addition, VNC by default uses TCP port 5900+N
, where N
is the display number. In this case, the :1
means that the VNC server will run on display port number 5901.
$ vncserver :1 -localhost -geometry 1024x768 -depth 32
To list VNC server sessions on your system, run the following command.
$ vncserver -list
Once the VNC server has started, check the port it is running on with the netstat command.
$ netstat -tlnp
vncserver -localhost no