• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

The Geek Diary

HowTos | Basics | Concepts

  • Solaris
    • Solaris 11
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VCS
    • VxVM
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Hadoop
    • Hortonworks HDP
      • HDPCA
    • Cloudera
      • CCA 131

How to configure VNC (Virtual Network Computing) in CentOS/RHEL 5,6

By admin

Virtual Network Computing (VNC) works by capturing the display’s frame buffer and making it available across the network. This recipe shows you how to install the basic VNC server and configure it to provide remote users access to their graphical desktop environment as if they were physically in front of the system.

Installing the basic VNC service

To install the prerequisite, run the appropriate command as root:

For CentOS/RHEL 6:

# yum install tigervnc-server tigervnc

For CentOS/RHEL 5:

# yum install vnc vnc-server

For VNC to be useful, it also requires that the X Windows System is installed along with a window manager. If a graphical desktop environment is not already installed, refer below post for the steps.

How to Install GUI for CentOS/RHEL 5,6,7

Configuring the VNC service

1. Edit the /etc/sysconfig/vncservers file to include the users it will start VNC servers for.

– Add a line to that file as follows:

# vi /etc/sysconfig/vncservers
VNCSERVERS="N:user"

Where,
N is the number of the display VNC server will be running and user is the username by which the server will be run as. (Usually starting at 1)

– Multiple displays and users can be specified by placing a space between them, as follows:

# vi /etc/sysconfig/vncservers
VNCSERVERS="N:user1 Y:user2"

2. Then the configuration of VNC should be customized for each individual user:

For CentOS/RHEL 6, add a line(s) to the file as follows:

# vi /etc/sysconfig/vncservers
VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 800x600  -nolisten tcp"

For CentOS/RHEL 5, add a line(s) to the file as follows:

# vi /etc/sysconfig/vncservers
VNCSERVERARGS[1]="-geometry 1024x768 -nohttpd"
VNCSERVERARGS[2]="-geometry 800x600  -nohttpd"

In the above example, the users configured to use displays N and Y (1 and 2 for our example) are now allowed to access VNC remotely if the ports are open on the machine’s firewall.

3. The firewall ports that will need to be opened for the example users, whom are using displays N and Y:

For user1: Open port 5901 (5900 + N), where we choose N as display 1.
For user2: Open port 5902 (5900 + Y), where we choose Y as display 2.

Note: If the X Window System is used for a local graphical environment, display 0 cannot be used for Xvnc as it is already being used by X. Also if vino-server is running on system then it won’t allow to use same display number for Xvnc. So it’s not recommended to run Xvnc and vino-server on the system at a time.

Configuring each user for VNC access

For each user specified, a VNC password needs to be set. VNC passwords are completely separate from the normal system password for that account. A user can set their VNC password by executing the vncpasswd command as shown below:

$ vncpasswd
Password:
Verify:
Note: root may run “vncpasswd username” command to set password for username, but this may lead to mistakes. The user should run the command vncpasswd by himself, which will create a directory ~/username/.vnc owned by the username.

By default, VNC starts up only a simple window manager and a terminal window. To enable a full Red Hat desktop environment over VNC, please refer to below post.

How to Configure vncserver to start GNOME or KDE by default in CentOS/RHEL

Starting the VNC service

1. In order to start the vncserver service immediately, run the following command:

# service vncserver start
Starting VNC server: 1:user1

2. In order for the vncserver service to start persistently after reboot, run the following command:

# chkconfig vncserver on 

3. The success of the command above can be verified by running:

# chkconfig --list vncserver
vncserver       0:off   1:off   2:off    3:on    4:on    5:on    6:off

Connecting with a VNC client

Now that VNC is running, vncviewer command can be used to connect from a remote Linux machine to the proper VNC-based X session. If the remote system is running Windows, a Windows-based VNC viewer program can be freely downloaded from the website http://www.tigervnc.org/.

# vncviewer vncserver-ipaddress:N

To connect to the user display using the vncviewer client, replace N with the number of the VNC-based X session for the desired user, as per the configuration in /etc/sysconfig/vncservers.

If connecting using a port number instead of display number, most vnc clients will require the syntax of vncserver-ipaddress::portnumber (ex. 127.0.0.1::5901).

Troubleshooting

These VNC-based X sessions must be left running when users are finished with them. They can do this by simply closing the vncviewer program instead of logging out. This maintains the state of the desktop so that when they reconnect, all their programs will be in the same state in which they were left.

If a user accidentally logs out from within a VNC-based X session they should follow these steps to get X working again:

  • Log in to the server as the user for whom VNC needs to be restarted.
  • Issue the command vncserver -kill :N
  • Run vncserver :N

If a connection to display issue is present, ensure that the resulting file has the execute bit set:

# chmod 755 ~username/.vnc/xstartup

Filed Under: CentOS / RHEL 4, CentOS/RHEL 5, CentOS/RHEL 6, Fedora, Linux

Some more articles you might also be interested in …

  1. RHEL 7 – RHCSA Notes – vi/vim editor
  2. Linux OS Service ‘haldaemon’
  3. CentOS / RHEL : How to extend Physical Volume in LVM by extending the Disk Partition used
  4. CentOS / RHEL 6,7 : How to delete an iSCSI Target on the initiator (iSCSI client)
  5. How to use wget to download file via proxy
  6. Sample /etc/multipath.conf file
  7. Linux OS Service ‘sysstat’
  8. Linux OS Service ‘smartd’
  9. How to create a VDO (Virtual Data Optimizer) device with the async/sync/auto write policy
  10. Linux / UNIX : How to create extended partition using fdisk

You May Also Like

Primary Sidebar

Recent Posts

  • How to set the order to load certain modules in CentOS/RHEL 7 and 8
  • How to configure initrd / initramfs to including kernel modules in CentOS/RHEL
  • How to configure systemd.path to trigger an event when any changes made to a directory
  • Script to monitor RMAN Backup and Restore Operations
  • Oracle RMAN Backup Shell Script Example
  • Archives
  • Contact Us
  • Copyright

© 2019 · The Geek Diary