• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to configure VNC Server on CentOS/RHEL 6

by admin

VNC (Virtual Network Computing) enables us to access the GUI of a remote system over a secured network. The VNC client installed on a local system captures the input events of a mouse and keyboard and transfers them to the remote VNC server. Those events are executed on a remote system and the output is sent back to the client. VNC is a desktop sharing tool and is generally used to access the desktop system for remote administration and technical support.

VNC Server and VNC client CentOS RHEL

To run VNC, you need two components:
1. VNC server
2. VNC viewer

Installing required packages

1. Check if the server is connected to Public/Private Yum Repo to avoid the dependency issue.

# yum repolist

2. For VNC to be useful, it also requires that the X Windows System is installed along with a window manager.

# yum install xorg-x11-apps

3. If a graphical desktop environment is not already installed, install it using the below commands.
Recommended

# yum groupinstall Desktop  "Desktop Platform" "X Window System"  "Internet Browser" "Graphical Administration Tools" Fonts

Minimal

# yum groupinstall Desktop "X Window System" Fonts

3. Install the vnc server RPMs:

# yum install vnc*

This installs latest version of RPMs: tigervnc-server-module, tigervnc and tigervnc-server.

Configuring VNC server

1. Edit the “/etc/sysconfig/vncservers” file to configure the required displays. The following entries enable VNC for display numbers “:2” and “:3“. Notice multiple “display:user” pairs are defined on a single line, but the arguments for each display are defined separately.

# vim /etc/sysconfig/vncservers
VNCSERVERS="2:root 3:user"
VNCSERVERARGS[2]="-geometry 1280x1024 -nolisten tcp -localhost"
VNCSERVERARGS[3]="-geometry 1280x1024"

The first line defines the user who is allowed to log in to the system. The second line lists the arguments passed to the VNC server when the service starts. Below are some of the most commonly used arguments in VNC server.

Argument Description
-geometry Defines the size of the viewer when the clinet connects
-nolisten tcp Defines TCP connection to the VNC server
-nohttpd Denies web VNC clients from connecting
-localhost Forces the use of a secure gateway (port forwarding)

2. Set the VNC password for all the users defined in the “/etc/sysconfig/vncservers” file. Make sure you set password for all the users defined in the configuration file /etc/sysconfig/vncservers.

# su - user        ### it is important to switch the user for which password needs to be set
$ vncpasswd
Password:
Verify:
# vncpasswd root
Password:
Verify:

3. Enable the “vncserver” service for autostart and start the service :

# chkconfig vncserver on
# service vncserver start
Starting VNC server: 2:root 
New 'geek.mylabserver.com:2 (root)' desktop is geek.mylabserver.com:2

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/geek.mylabserver.com:2.log

3:user 
New 'geek.mylabserver.com:3 (user)' desktop is geek.mylabserver.com:3

Creating default startup script /home/user/.vnc/xstartup
Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/geek.mylabserver.com:3.log

                                                           [  OK  ]

4. Run the “vncserver” command to start or stop the vncserver. By default the user who fires the “vncserver” command, the session for that user is started.

# vncserver 

New 'geek.mylabserver.com:1 (root)' desktop is geek.mylabserver.com:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/geek.mylabserver.com:1.log

How to list and kill VNC server sessions

To list all the currently running tigerVNC server session use the command “vncserver list”. For example :

# vncserver -list

TigerVNC server sessions:

X DISPLAY #	PROCESS ID
:4		1864
:5		1895
:6		1923
:1		1949
:2		1767

To kill any of the running VNC server sessions, use the command shown below.

# vncserver -kill :4
Killing Xvnc process ID 1864

Here,
:4 is the X-display session number.

Troubleshooting VNC server configuration

If you do not switch to the user you want to set the VNC server password for, you may get an error as shown below while starting the vncserver service.

# service vncserver start
....
3:user 
You will require a password to access your desktops.

getpassword error: Inappropriate ioctl for device

Connecting VNC server from VNC client

You can install any VNC viewer software on your client machine to access the VNC server. I am using realVNC software on my MAC to access the VNC server. You can use any of the below VNC viewer softwares according to the OS you are using.
1. TigerVNC: http://tigervnc.org
2. TightVNC: https://www.tightvnc.com/download.php
3. RealVNC: https://www.realvnc.com/en/connect/download/viewer

To connect the VNC server with root user use the display (:1). This is the same display you got for root user when you started the VNC server with “vncserver” command.

connect to VNC server with VNC viewer

You might get a warning as shown below, which is telling you that your connection with the VNC server is not secure.

configure VNC server RHEL CentOS 6

Proceed to the next screen and put the password you have set with “vncpasswd” command for root user.

installing and configuring VNC server and VNC clinet in CentOS RHEL 6

There you are!!! You are now connected to the VNC server.

tiger VNC server configuration in Linux

Filed Under: CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL 5,6 : How to reinstall GRUB loader from rescue mode
  2. Cannot Increase “nproc” Value More Than 1024 in CentOS/RHEL 6
  3. How to Check if a Service Restart or Server Reboot is required After RPM Package Update (CentOS/RHEL/Fedora)
  4. ansible-playbook: command not found
  5. w: command not found
  6. How to delete a non-root use with UID 0 in Linux
  7. daemonize Command Examples in Linux
  8. How to disable a specific command for a specific user in Linux
  9. Linux OS Service ‘nscd’
  10. firewall-cmd Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright