How to Install and Configure VNC Server in RHEL

Install Tiger VNC Server

#yum install tigervnc-server* -y

On legacy distribution. you may not able to find tighervnc RPM.for legacy OS use below cmd to install VNC

#yum install vnc -y

Configure VNC

The first configuration step is to edit the /etc/sysconfig/vncservers file. At the end of that file, enter the following:

For Single User

#vi /etc/sysconfig/vncservers
VNCSERVERS="1:oracle"
VNCSERVERARGS[1]="-geometry 800x600"

The first line defines the user who is allowed to log in to the system. The second line lists arguments passed to the VNC server when the service starts.

-geometry Defines the site of the viewer when the client connects
-nolisten tcp Denies TCP connections to the VNC server
-localhost Forces the use of a secure gateway (port forwarding)

The number that appears (1 in this case) is the number of the session for defined user. The VNC server runs on port 5900, but the actual port that will used is 5900 + the number defined = 5901 in this case.

NOTE: geometry is the screen resolution.you can change it if you want.

Set the VNC password for the user, you must first su to that user account. Issue the vncpasswd command.

#su  oracle
#vncpasswd

For Multiple Users

you can set up multiple users for VNC. suppose you have 2 users that needed access using different resolutions. To accomplish this, you could enter something like

VNCSERVERS="1:oracle 2:shabbir"
VNCSERVERARGS[1]="-geometry 800x600"
VNCSERVERARGS[2]="-geometry 1200x800"

Note: 1:oracle (“1” is session No and “oracle” is the user name) and 2:shabbir (“2” is session No and “shabbir” is the user name)

Configure xstartup Script

You now need to go into each user that will be logging in with VNC and editing their ~/.vnc/xstartup script. Within that script, you should find the following:

xstartup file syntax

#!/bin/sh

# Uncomment the following two lines for normal desktop:
#unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

User-1 Configuration (oracle)

Set the VNC password for the user, you must first su to that user account. Issue the vncpasswd command.

#su  oracle
#vncpasswd

Go to oracle user vnc directory and edit the xscript file

NOTE: Sometime you may not able to find xstartup file in .VNC directory, in that case don’t worry.copy the xstartup file syntax from above and create file manually or start the VNCServer Service.it will create xstartup script file automatically.

#cd /home/oracle/.vnc
#vi xstartup

uncomment following lines (remove the “#” characters from start of the line)

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Save the file

User-2 Configuration (Shabbir)

Set the VNC password for the user, you must first su to that user account. Issue the vncpasswd command.

#su  shabbir
#vncpasswd

Go to Shabbir user vnc directory and edit the xscript file

NOTE: Sometime you may not able to find xstartup file in .VNC directory, in that case don’t worry.copy the xstartup file syntax from above and create file manually or start the VNCServer Service.it will create xstartup script file automatically.

#cd /home/shabbir/.vnc
#vi xstartup

uncomment following lines (remove the “#” characters from start of the line)

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Save that file.

Start VNC Service

#service vncserver start

If already on then restart the Service

#service vncserver restart

Make sure VNC service Run at Startup

#chkconfig vncserver on

Linux Firewall Configuration

if you are using linux firewall (iptables). then you should open the vnc port in order for the VNC connections to get through.

For Single User

#iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5901,6001 -j ACCEPT

Save the file and restart iptables with the command:

For multiple Users

#iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT

Save the file and restart iptables with the command:

#Service iptables save
#service iptables restart

Little Tip
To check the vnc process to make sure its working correctly.

#ps -aux|grep -i vnc 

Output

oracle   14029  1.0  0.2 13356 9592 pts/0    S    09:33   4:07 Xvnc :1 -desktop ROraVision01.sngpl.com.pk:1 (oracle) -httpd /usr/share/vnc/classes -auth /home/oracle/.Xauthority -geometry 800x600 -depth 16 -rfbwait 30000 -rfbauth /home/oracle/.vnc/passwd -rfbport 5901 -pn

Note:you will find the user session id and user name from above output.here is specific part of the output “Xvnc :1 -desktop ROraVision01.sngpl.com.pk:1 (oracle)”

Test the VNC Connection

Option 1: With Browser (Linux/Windows)

You can actually test this with a browser (if Java is installed on the machine). To do this, open up the browser and go to http://ADDRESS_OF_VNC_SERVER:5801. That address should open up a VNC session in your browser. If it does not… try the address http://ADDRESS_OF_VNC_SERVER:1.

Option 2: Using VNC Client (In Linux)

Go to Linux Machine. install the VNC rpm.

yum install tigervnc 

To access, open a command terminal, and type in vncviewer

#vncviewer

You will be prompted for an IP address to connect to. Enter this, and click OK. You should now have remote control of another PC

Option 2: Using VNC Client (In Windows)

Download VNC viewer Windows client from http://www.realvnc.com/download/viewer/
Run the VNC Setup. while installation only choose VNCViewer as shown below.

VNC-1

When installation finished .run the vncviewer and enter the VNC server address with session ID. in my case it is 10.0.7.173:1. Click “Connect”

VNC-2
Note: every session ID is designated to different user if you had configured multiples.

In next screen it will ask you to enter the password make sure enter the correct user password which is designated to session ID 1. this is the same password which you was set using vncpasswd command.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s