Did You Know?
Donate to TecMint

LFCS - Linux Foundation Certified SysAdmin - Exam Preparation Guide

Install TightVNC Server in RHEL/CentOS and Fedora to Access Remote Desktops

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

Virtual Networking Computing (VNC) is a Kind of remote sharing system that makes it possible to take control of any other computer connected to internet. Keyboard and mouse clicks can easily transmit from one computer to another. It helps administrator and technical staff to manage their servers and desktops without being to the same location physically.

VNC is an open source application created in late 1990’s. It is independent and is compatible with Windows and Unix/Linux. Means a normal Windows based user can interact with Linux based system without any hazel.

To use VNC you must have TCP/IP connection and VNC viewer client to connect to a computer running VNC server component. The server transmits a duplicate display of a remote computer to the viewer.

This artilce demonstrates how to install VNC Server using TightVNC a much enhanced version of a older VNC program, with GNOME Desktop remote access on RHEL, CentOS and Fedora systems.

Step 1: Installing GNOME Desktop

If you’ve installed a minimal version of Operating System, which gives only a command-line interface not GUI. Then you need to install a GUI (Graphical User Interface) with GNOME Desktop. The GNOME desktop provides a lightweight desktop environment that works very well on remote VNC desktops.

[root@tecmint ~]# yum groupinstall "X Window System" "Desktop"

Step 2: Installing TightVNC Server

TightVNC a remote desktop control software that enables us to connect to remote desktops. To install, use the following yum command as shown below.

[root@tecmint ~]# yum -y install tigervnc-server xorg-x11-fonts-Type1

Step 3: Create a Normal VNC User

Create a normal user, that will be used to connect to remote desktop. For example, I’ve used “tecmint” as a user, you can choose your own username.

[root@tecmint ~]# useradd tecmint
[root@tecmint ~]# passwd tecmint
Changing password for user tecmint. 
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

Step 4: Set VNC Password for User

Create a new password for newly created user. Login to the user (su – tecmint) and run ‘vncpasswd‘ to set the VNC password for the user.

Note : This password is for accessing VNC remote desktop, and the password we created in step 3 is for accessing SSH.

[root@tecmint ~]# su - tecmint
[tecmint@tecmint ~]$ vncpasswd
Password:
Verify:

The above command ask you to supply password twice and creates “.vnc” directory under user’s home directory with passwd file inside it. You can check the password file is created, by using following command.

# ls -l /home/tecmint/.vnc
-rw------- 1 tecmint tecmint 8 Jul 14 21:33 passwd

Now exit from user login and return to root user login.

[tecmint@tecmint ~]$ exit
exit

Step 5: Create VNC Xstartup Script

Create the xstartup script as root user. This can be created by starting the VNC server.

[root@tecmint ~]# /etc/init.d/vncserver start

Starting VNC server: 1:tecmint 
New 'tecmint.com:1 (tecmint)' desktop is tecmint.com:1

Starting applications specified in /home/tecmint/.vnc/xstartup
Log file is /home/tecmint/.vnc/tecmint.com:1.log
						 [  OK  ]

Next, check whether xstartup script is created under (tecmint) user’s home directory, do “ls -l” command.

[root@tecmint ~]# ls -l /home/tecmint/.vnc/
-rw-------. 1 tecmint tecmint    8 Jul 15 12:27 passwd
-rwxr-xr-x. 1 tecmint tecmint  654 Oct 11  2012 xstartup

Once, it created,  set a desktop resolution in xstartup file. For this, you must stop running VNC service.

[root@tecmint ~]# /etc/init.d/vncserver stop

Shutting down VNC server: 1:tecmint              [  OK  ]

Step 6: Setting Xstarup Resolution

Open file “/etc/sysconfig/vncservers” file your choice of editor. Here I’m using “nano” editor.  Create new VNC Session for “tecmint” with below command. where “-geomerty” is used define desktop resolution.

[root@tecmint ~]# nano /etc/sysconfig/vncservers

And add following lines to it at the bottom of file. Save and close it.

## Single User ##
VNCSERVERS="1:tecmint"
VNCSERVERARGS[1]="-geometry 1280x1024"

If you’re dealing with multiple users, first create a vncpasswd for all user’s as described above in step 4, and then add those user’s to the VNCSERVERS line and add a VNCSERVERARGS[x] entry as shown below. Where ‘x‘ is the ID number.

## Multiple Users ##
VNCSERVERS="2:ravi 3:navin 4:avishek"
VNCSERVERARGS[2]="-geometry 1280x1024"
VNCSERVERARGS[3]="-geometry 1280x1024"
VNCSERVERARGS[4]="-geometry 1280x1024"

Step 7: Starting TightVNC Server

After making all changes, run the following command to start again the VNC server. Before starting VNC session to “tecmint” user, let me give you a small intro about Port Numbers and ID‘s. By Default VNC runs on Port 5900 and ID:0 (which is for root user). In our scenario I’ve created tecmint, ravi, navin and avishek. So, the ports and id’s are used by these users as follows

User's		Port's		ID's
5900		root		:0
5901		tecmint		:1
5902		ravi		:2
5903		navin		:3
5904		avishek		:4

So, here user “tecmint” will get port 5901 and id as :1 and so on. If you’ve created another user say (user5) then he will get port 5905 and id:5 and so on for each user you creates.

[root@tecmint ~]# /etc/init.d/vncserver start

Starting VNC server: 1:tecmint 
New 'tecmint.com:1 (tecmint)' desktop is tecmint.com:1

Starting applications specified in /home/tecmint/.vnc/xstartup
Log file is /home/tecmint/.vnc/tecmint.com:1.log

2:ravi 
New 'tecmint.com:2 (ravi)' desktop is tecmint.com:2

Starting applications specified in /home/ravi/.vnc/xstartup
Log file is /home/ravi/.vnc/tecmint.com:2.log

3:navin 
New 'tecmint.com:3 (navin)' desktop is tecmint.com:3

Starting applications specified in /home/navin/.vnc/xstartup
Log file is /home/navin/.vnc/tecmint.com:3.log

4:avishek 
New 'tecmint.com:4 (avishek)' desktop is tecmint.com:4

Starting applications specified in /home/avishek/.vnc/xstartup
Log file is /home/avishek/.vnc/tecmint.com:4.log

                                                           [  OK  ]

Step 8: Open VNC Ports on Firewall

Open port on iptables, say for user (tecmint) at 5901.

[root@tecmint ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

For multiple users, ravi, navin and avishek. I open ports 5902, 5903 and 5904 respectively.

[root@tecmint ~]# iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -m multiport --dports 5902:5904 -j ACCEPT

Restart Iptables service.

[root@tecmint ~]# service iptables save
[root@tecmint ~]# service iptables restart

Step 9: Download VNC Client

Now go to your Windows or Linux machine and download VNC Viewer client and install in your system to access the desktop.

  1. Download VNC Viewer

Step 10: Connect to Remote Desktop Using Client

After you installed the VNC Viewer client, open it you’ll get similar to below screen. Enter VNC Server IP address along with VNC ID (i.e 1) for user tecmint.

VNC Server Login Details

Enter VNC Server IP Address

Enter password that we created with “vncpasswd” command.

Enter VNC User Password

Enter VNC User Password

That’s it, you connected to your Remote Desktop.

VNC Remote Desktop

VNC Remote Desktop

Read Also : Access VNC Desktop from Web Browser

Reference Link

TightVNC Homepage

Ravi Saive

Owner at TecMint.com
Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.

Your name can also be listed here. Work as a Paid freelancer/writer at TecMint.
Download Free eBooks
Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

25 Responses

  1. On my fresh install Centos 6.4, I had to invert step 5 and 6.

    It refuses to start because no resolution was setup.

    • Mohd imran says:

      hi,

      this is Imran raini from Mumbai.
      I have Linux Server that is Linux 6.0 version
      I want to install VNC on that server. please help me
      I try to install VNC but it is not install Proper kindly send me step how can install VNC in Linux 6.0 Server.

      Best Regards
      Mohd Imran Raini

  2. Dave Matheis says:

    I have been having trouble with this under Fedora since version 18. Under Gnome 3.6 I could set it in forced fallback mode and using the Cinnamon desktop could get it to work. Now with gnome 3.8 there is no fallback mode option. I went all through your setup instructions, with modification for using systemctl to start/stop vncserver, and it all seems to work fine until I enter the VNC password. The remote desktop window opens but says “Oh no! Something has gone wrong. A problem has occurred and the system can’t recover. Please log out and try again.”

    I have been searching the web for a solution to this for nearly a year and so far have not had any luck getting it to work. Any ideas?

    Thanks,

    Dave

    • Sidney Markowitz says:

      I had a messy setup working for Cinnamon under Fedora 18, but got the “Oh no!” again after upgrading to Fedora 19. However now it appears that there is a much simpler solution in Fedora 19. Install tiger-vncserver, copy file vncserver@.service to vncserver@:1.service and edit to replace the two uses of to the correct user name and add the -geometry and -depth options you want to the vncserver command line, just like you would to use vnc with the Gnome desktop.

      Then to make it use Cinnamon, create a script file named ~/.Xclients that contains

      #!/bin/bash
      exec /usr/bin/cinnamon-session

      When the vnc session starts up it runs ~/.Xclients if it exists instead of starting gnome-session.

      The cinnamon-session program appears to be new in Fedora 19 and solves the problem.

      • Radek Lát says:

        Thank you so much for this comment. I spent several hours trying to get the same thing to work without any success. Your solution works for me as well and it’s so simple!

  3. Arrey says:

    Thanks for this post.
    How will you tunnel vnc via ssh?

    Thanks

  4. tarun says:

    im facing connection : Connection time out (10060).

    my telnet is working fine..
    telnet 172.31.0.212 5901
    Trying 172.31.0.212…
    Connected to 172.31.0.212.
    Escape character is ‘^]’.
    RFB 003.008

    some one help me out. im having my aws linux machine and accessing it from local machine.

  5. brandon says:

    Thank you!

  6. shamrat says:

    I followed the steps on my centos 6.5 final VPS trying to connect from windows 7 but is says “connection refused (10061)” I also tried telnet from comments above on SSH it says telnet: connect to address xxx.xxx.xxx.xxx: Connection refused

    can anybody help? Thanks in advanced

  7. shamrat says:

    hi, I have managed to configure the vnc but when I log in there are some files that I can not edit/delete as vncuser, how can I give vnc user root lever access I have tried to do something like: vncserver:0;0…… to give it root access on users file. But now I cant log in to vnc either.

  8. venkat says:

    how to resolve too many security failures vnc server how to check vnc server logs and how check which ip address are connected to vnc server please guide me

    • Ravi Saive says:

      Under user’s home directory you will see a .vnc directory where you can see the log file of each vnc session like ‘mymachine.localnet:1.log’. And about checking vnc connection sessions, you can use netstat command to list vnc ports or use ps -fax to check running vnc services.

  9. Maki says:

    Hi, thank you for a nice tutorial.

    I do my work thru VNC, connecting to a remote server. I often encounter problems though when running some applications, I cannot use my keyboard to input on the GUI, thus I cannot type anything on the fields for the gui of this particular app.

    Everything works fine on a simple linux shell.

    Thank you

  10. soo says:

    Hi. Thank you for your posting.

    I’m now using CentOS6.5.

    /etc/init.d/vncserver start

    Error: bad escape code: f [FAILED]

    I have this error. What is the problem???

    thank you.

  11. Madhu says:

    I have installed VNC as per above tutorial

    now Vnc viewer is asking for session password after keeping the server in idel conditins for some time..when i entered the login password its not working

    kindly suggest what can be done

  12. MotherDawg says:

    Oh Boy ! ***************************************************************

    Close but no cigar…

    @ Ravi

    1st, at the end of step 5, you write:
    “Once, it created, set a desktop resolution in xstartup file. For this, you must stop running VNC service.”

    The at the beginning of step 6 you go:
    Open file “/etc/sysconfig/vncservers” file your choice of editor. Here I’m using “nano” editor. Create new VNC Session for “tecmint” with below command. where “-geomerty” is used define desktop resolution.

    ??? Ambiguous file references ???

    In xstartup in the user’s home directory or in /etc/sysconfig/vncservers do we add the Resolution setting code ?

    2nd, This is ok for sysint and iptables. If, like the gentlemen named Matheis, as of the date of publication of this article, one would be using an advance distribution like Fedora 18, out Jan 15 2013 this article is already old school.

    With systemd and firewalld, most of this nice try does not work.

    MotherDawg
    Aka: NetWeezurd

    • Keshav says:

      Hey my fedora too required me to tweak around the systemd. Could you create a page with how to set up vnc with config files under systemd

  13. boat says:

    after “/etc/init.d/vncserver start” vncserver listen in 127.0.0.1:5902
    how to specify vncserver listen ip.

  14. Keshav says:

    Worked for me thanks!! :)

  15. mohamad says:

    hi

    my problem is in step 5
    when i try to open commend : /etc/init.d/vncserver start

    this error showing :

    Starting VNC server: no displays configured [FAILED]

    on centos-6-x86

  16. James Roger says:

    Above steps seems to be quite complicated. I would recommend using a RHUB remote support servers for remotely accessing computers. It is easy to use.

  17. DJ MHA says:

    Thanks for great efforts. It working great. Can you tell us how to uninstall it properly?

  18. luke says:

    hi i did all steps and try start the service get this error
    /etc/init.d/vncserver start
    plymouth: ply-event-loop.c:493: ply_event_loop_new: Assertion `loop->epoll_fd >=
    0′ failed.
    /etc/init.d/functions: line 543: 28173 Aborted /bin/plymouth –d
    etails

    system: centos6.4

    please help sending me crazy

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.