How to Configure vncserver in Fedora

Vnc server and vnc viewer is used to Remote Access in most of the Linux machines like Fedora, RHEL, Ubuntu or any other Linux distro. Sometimes it is necessary for System Administrators and developers to access a Linux machine remotely. Usually things can be done via SSH but you cannot do graphical stuffs using SSH. It’s just a text based command line utility.

Think of vnc as a remote display. Basically you can’t see the display biut whenever you will login to the particular display number then you will see from where you left unlike ssh where all the previous session is gone and you start afresh.

How to configure vncserver in Fedora Linux

Here I will show you how to configure VncServer on a Fedora machine. The configurations will be mostly similar in other Linux distros too.

Install and Configure VncServer :

Installing Vnc Server on a Fedora machine:

yum is the utility used to install any application package on Fedora. So we will go ahead and use the same to install Vnc server.
Enter the following command with root privilege on your Fedora machine:

This should install the vncserver on your machine. Important is configuring vncserver so that you can access it from a remote location.

Configuring Vnc Server on a Fedora machine:

If you have a Fedora system with version 18 or earlier then the configuration vncserver is much simpler as compared to the later versions.

Configure vncserver the following way if you have fc18 (Fedora 18) or earlier:
Vnc server is running as a service. The vnc server service uses the /etc/sysconfig/vncservers config file to configure vnc server.

......
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
# Different display numbers for different users
VNCSERVERS="1:root 1:user2 2:user2 3:user3"
# Set arguments for display#1 (which is root in this case)
VNCSERVERARGS[1]="-geometry 800x768"
# Set arguments for display#2 (which is root in this case)
VNCSERVERARGS[2]="-geometry 1024x768"
# Set arguments for display#3 (which is root in this case)
VNCSERVERARGS[3]="-geometry 1024x768"

You can observe the VNCSERVERS=”1:root 1:user2 2:user2 3:user3″ has 1:root and 1:user2 both in the username arguments which means the display number 1 can be accessed by both root and user1. I hope you understand what am I trying to convey. If you remember I had told at the first of this post that think of vnc as multiple remote displays.

Configure vncserver if you have fc19 (Fedora 19) or later version:
For fc19 or later, path to the vncserver configuration file has been changed from /etc/sysconfig/vncservers to /etc/sysconfig/vncservers. The earlier file is still present which only has some text that tells the file has been moved to the later location. Even some of the configuration parameter has been changed.

Then edit individual files and change the user settings. For example:
Open the /etc/systemd/system/[email protected]:1.service for and add parameters for say user1 (make sure to change user1 to username used on your system):

Vnc server configuration is DONE now but still you cannot access because we need to set password for individual users. Its time to set a password for a vnc user. This password is only used when the vncserver is accessed via vncviewer from a remote machine or a client.

Follow the below command on the command line to set a password for a specific vnc user lets say user1:

Enter the password and the system is ready to be accessed via vnc viewer for the user user1. Similarly do the same for other users. Make sure to change the user1, user2 to specific usernames on your system.

The above command will start a vncserver on the display number 1. The configuration for the display number 1 will be taken from VNCSERVERS=”1:root” argument in fc18 or earlier and from the /etc/systemd/system/[email protected]:1.service config file in fc19 or later.
Similarly you can start N number of displays.

The above command should work in all Fedora versions. If that does not work for newer versions then you can enter the following command: