Install and Configure VNC Server for Remote Access on Linux

Like RDP, VNC protocol allows for accessing computers remotely with full window GUI. It’s used in VMware vSphere and OpenStack for users to interact with virtual machines by connecting to hypervisors. Here is what I just did to set it up. The instruction should work on a host either it’s a physical machine or virtual machine as long as it’s installed with CentOS or equivalents.

Installing VNC Server

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

The numbers 1, 2, etc., in the file stands for the ID for the port assigned for each user. You add base port number 5900 to get the corresponding port number. For exmaple, the 1 maps to port number 5901 of TCP. The 1024×768 as you can guess is the screen resolution, and the 16 is the depth of color. The bigger the resolution or the depth, the more traffic will flow on the wire.

For a complete list of the resolutions your X windows supports, you can type in the following command in bash:

To authenticate the remote access, you need to create VNC password for each user involved. The password is saved into .vnc directory under each user’s home directory. To make life easy, you can use the same password for login even though it’s not recommended for security reason.

# su - cloud
$ vncpasswd
$ cd .vnc
$ lspasswd
$ exit

# su - cloud
$ vncpasswd
$ cd .vnc
$ ls
passwd
$ exit

Run VNC Server and Make it Always On

Although the VNC server is installed by default, it’s not run as a service by default. In other words, you still need to run it manually as follows:

# service vncserver start

# service vncserver start

Still, we want the VNC run every time the OS boots. This is actually as easy as running any other services on Linux:

# chkconfig vncserver on

# chkconfig vncserver on

Open Up the Firewall

By this far, you are supposedly able to access the VNC server just configured. Unless you have turned off your firewall, the chance is you cannot yet access your machine from any other host than itself with vnc viewer.

The solution is very simple, either turn off firewall which I don’t recommend, or open the related ports. As the above configuration, you need to open up the TCP ports 5901 and 5902. On CentOS, it’s easy via GUI (System – Administration – Firewall, select Other Ports from left pane and add port there.) Again, don’t forget to click on the Apply button on the toolbar for the change to take effect immediately. You can also do it directly with iptable commnad line if you are familiar with the iptable.

Fix Authentication Issue
When connecting to a VNC server, you may see a dialog box on the screen whose title is “Authenticate” and the content says “Authentication is required to set the network proxy used for downloading packages. An application is attempting to perform an action that requires privileges. Authentication as the super user is required to perform this action.” You can enter root password there and click “Authenticate” button. The annoying part is that the next time you restart your OS, this dialog box comes back again.

If you want to turn it off, here is an easy fix:

$ gnome-session-properties

$ gnome-session-properties

You will see an application windows showing up. Scroll the list and un-checked PackageKit Update Applet. You won’t see the annoying dialog box after that.

NEED HELP?

My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.