VNC is used to display X windows session running on a remote server. For network engineers, it is really useful to have Konsole/xterm session running on a Linux server connecting to network devices. Whenever we need access to the switches/routers, we can just login to VNC server using a VNC client. All sessions will be active (unless idle timeout is configured on switches/routers) and ready to use.
Steps to install VNCserver in Linux:
- Make sure atleast one windows manager package like gnome, kde is installed. Not mandatory.
- Install VNC server using “yum install vnc-server”
- Make sure to start the VNC-server service using: “service vncserver [start | stop | status]”
- VNC-server runs on port: 5900. Make sure this port is not blocked by any Firewall/ACL.
[root@linux-1 ~]# netstat -an | grep 5900 tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN
- Type “vncserver” to create a Xvnc session for the current user. If it is first time, it will ask for password to connect to the vnc session. We can change the password later using “vncpasswd” command.
- For eg: “vncserver -name venkat :87 -geometry 1366×768” will create a Xvnc session with desktop name “venkat” and display number :87 with user defined screen resolution.
- We need this display number to connect from vnc client: “[server IP]: display#”. Check the vnc log file under /.vnc folder to find the port on which vnc connections are accepted.
- Use “vncserver –kill :display#” to kill/stop the Xvnc process running for that display#.
- A default “xstart” file will be created under “/home/[user]/.vnc”. This file has the list of applications to invoke while starting the server.
[root@linux-1 .vnc]# cat xstartup #!/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 & # to start the vncconfig window to copy clipboard info xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & # to start xterm terminal twm & # to load timeless window manager. Default. Comment if another WM is used #startkde & # Uncomment to start KDE desktop. #startx & # Uncomment to start GNOME session. "exec gnome-session" can also be used.
- Make sure to load only one desktop environ. If you plan to stop one desktop manager and start another, use “ps –U <username>” and get the process ID of kde/gnome/twm and kill that process- “kill -9 <pid>” before starting another.
- VNCserver can automatically allocate display number from 1-99. (99 sessions). If all 99 sessions are used, we need to manually provide the display number while creating the session.