Starting a user’s VNC server automatically on Linux


On some Linux systems, it can be advantageous for users to have a way to login to a console. Unfortunately, if they do not have physical access to the machine, there needs to be a way to do it remotely. Fortunately on Linux, there is Virtual Network Computing (VNC). VNC can be set up as a server and I will outline the steps necessary to complete this task.

First, ensure that vncserver is installed on your system. For Red Hat systems type:

>yum list vnc-server

If you see the following message:

Loaded plugins: rhnplugin
Error: No matching Packages to list

You will  need to install vncserver. Using Yum again:

>yum -y install vnc-server

We can now begin configuring VNC. We are going to do this for two users, root and myuser. Each user will access their virtual desktop from separate Internet Protocol ports. Vtxinst will use port 5801 and root will use port 5802.

We first need to edit /etc/sysconfig/vncservers. On line that has

# VNCSERVERS=”2:myusername”

Change it to

VNCSERVERS=”1:myuser 2:root”

Save the file. Now we need to prime VNC to setup its supporting files correctly. Login first as root, then myuser and issue the following command:

>vncserver

You will be prompted for a password if this is the first time this user has started VNC. Then run the following command to stop vncserver:

>vncserver -kill :1

Next let’s edit the user’s ~/.vnc/xstartup so that we use the gnome desktop instead of X windows. In the user’s directory, edit the file ~/.vnc/xstartup and uncomment the following 2 lines by removing the # so that the two lines look like the following:

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Finally, enable vncserver on startup with the following command:

>chkconfig –levels 35 vncserver on

Now, next time you reboot, VNC server will start automatically. If you don’t want to reboot, then run:

>service vncserver start

And VNC server will now be running!

, ,