How to Configure vncserver in Fedora Linux
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.
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:
[[email protected]]# yum install vnc-server
or the below command:
[[email protected]]# 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="-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="-geometry 800x600 -nolisten tcp -localhost" VNCSERVERS="1:root" VNCSERVERARGS="-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:
[[email protected]]# vim /etc/sysconfig/vncservers
...... # VNCSERVERS="2:myusername" # VNCSERVERARGS="-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="-geometry 800x768" # Set arguments for display#2 (which is root in this case) VNCSERVERARGS="-geometry 1024x768" # Set arguments for display#3 (which is root in this case) VNCSERVERARGS="-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:
[[email protected]]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]
Now edit the copied file and change the parameters as desired. I will demonstrate the configuration for ROOT user.
[[email protected]]# vim /etc/systemd/system/[email protected]
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 [email protected] to [email protected], [email protected] and so on.
If you want to add multiple display numbers then you can copy the [email protected] to [email protected]:1.service, [email protected]:2.service and so on.
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):
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:
[[email protected]]$ su - user1 [[email protected]]$ vncpasswd Password: Verify: [[email protected]]$ su - user2 [[email protected]]$ 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:
[[email protected]]$ vncserver :1
enter the following command to start vnc server with a particular resolution:
[[email protected]]$ 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/[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:
[[email protected]]# systemctl start vncserver-user1@display_number.service
[[email protected]]# systemctl start [email protected]: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:
[[email protected]]# 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.
You might also like
When you are starting to learn Linux programming or Device driver development, then the first thing you need is the Linux Kernel which is available in a zipped archive format
Sometimes you wanted to change the Hostname on a Linux machine like on your Ubuntu PC or a Fedora machine or any other Linux distro like a Citrix XenServer to
Wondering how to learn Linux without having a Linux PC with you?? Is it really possible or you’re just kidding me?? Trust me it’s all possible and you just need