Thursday, May 31, 2012

Easy Way to Configure VNC Server On Linux

Make sure that VNCserver package is already installed:
# rpm -qa | grep vnc-server

If not installed:
Download the latest version of VNC server from this link:

Note: Server Free Edition has no security feature available.

Install VNC server on your server:
# rpm -Uvh VNC-Server-5.2.0-Linux-x64.rpm 

Modify the VNC config file:
# vi /etc/sysconfig/vncservers
Add these lines at the bottom:
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

Set a password for VNC: 
# vncpasswd

Start a VNC server session just to generate the default config files:
# vncserver :1

Note: It's recommended to not run VNC server as root, as this will allow connected users to have root privileges once they connect via VNC.

Configure VNC to start an Xsession when connecting:
# vi ~/.vnc/xstartup
UN-hash these two lines:
 exec /etc/X11/xinit/xinitrc

Start a VNC session on the machine: 
# vncserver -kill :1
# vncserver :1

Now you can login from any machine (your Windows machine) using VNCviewer to access that remote server using port 5900 or 5901. make sure these port are not blocked by the firewall.
VNC Viewer can be downloaded from this link:

Note: If you close that vnc session without logout you can re-login again to the same used session,
but if you logout from that session you have to re-issue the previous two commands again on the server:

# vncserver -kill :1
# vncserver :1

or just do it in one command:
# service vncserver restart

To disable VNCserver and kill current connected VNC sessions:

# service vncserver stop
or use:
# vncserver -kill :1

I hope that was easy and clear.

No comments:

Post a Comment