How to Configure vncserver in Fedora Linux


Gaming Laptop Series

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.

configure vnc server in fedora

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:

[root@linuxlinuxlinuxlinuxlinux]# yum install vnc-server

or the below command:

[root@linux]# yum install tigervnc-server

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.

The above file should look something like this:

# vim /etc/sysconfig/vncservers
......
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

If you want to configure the vncserver for only root user then do the following modification on the above file after the last line:

# vim /etc/sysconfig/vncservers
......
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768"

If you want to configure the vncserver for multiple users then do the following modification on the above file after the last line:

[root@linux]# vim /etc/sysconfig/vncservers
......
# 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.

First copy the configuration file:

[root@linux]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service

Now edit the copied file and change the parameters as desired. I will demonstrate the configuration for ROOT user.

[root@linux]# vim /etc/systemd/system/vncserver@.service
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/root/.vnc/%H%i.pid

If you want multiple users to access vnc server then go to /etc/systemd/system/ directory, copy the vncserver@.service to vncserver-user1@.service, vncserver-user2@.service and so on.
If you want to add multiple display numbers then you can copy the vncserver@.service to vncserver@:1.service, vncserver@:2.service and so on.

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

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/home/user1/.vnc/%H%i.pid

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:

[some_user@linux]$ su - user1
[user1@linux]$ vncpasswd
Password:
Verify:
[some_user@linux]$ su - user2
[user1@linux]$ vncpasswd
Password:
Verify:

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.

How to start vncserver :

Follow the below command to start vncserver:

[some_user@linux]$ vncserver :1

enter the following command to start vnc server with a particular resolution:

[some_user@linux]$ vncserver :1 -geometry 1024x768

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/vncserver@: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:

[root@linux]# systemctl start vncserver-user1@display_number.service
[root@linux]# systemctl start vncserver-root@:1.service

How to STOP vncserver:

If you feel like the vncserver is not working or you need to restart it the you know how to start it but see the below command to stop a vncserver:

[root@linux]# vncserver -kill :1

The :1 is for display number. If you want to stop display number 5 then replace :1 with :5.

That’s all folks. Vncserver is up and running. The next thing is to access the running vncserver from a vncviewer or a client which I will write in a later post.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.