VNC
VNC is used to display an X windows session running on another computer. Unlike a remote X connection, the xserver is running on the remote computer, not on your local workstation. Your workstation ( Linux or Windows ) is only displaying a copy of the display ( real or virtual ) that is running on the remote machine.
01. Install the vnc-server rpm if not already installed
# yum install vnc-server
02. Make sure to install a window manager in order to get a normal GUI desktop if not alreday installed
# yum groupinstall "GNOME Desktop Environment"
03. Create VNC users
# useradd user1
# useradd user2
# passwd user1
# passwd user2
04. Create VNC password for each user. This will create the .vnc directory in the respective home directory
# su - user1
# vncpasswd
# su - user2
# vncpasswd
05. Edit /etc/sysconfig/vncservers, and add the following to the end of the file
VNCSERVERS="1:user1 2:user2"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1280x1024"
User1 will have 1024x768 screen and user2 will have 1280x1024
06. Create xstartup scripts by starting and stopping the vncserver as root
# /sbin/service vncserver start
# /sbin/service vncserver stop
Login to each user and edit the xstartup script. To use user1 as an example, first login as user1
$ cd .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 &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Add the line indicated below to assure that an xterm is always present, and uncomment the two lines as directed if you wish to run the user's normal desktop window manager in the VNC. Note that in the likely reduced resolution and color depth of a VNC window the full desktop will be rather cramped and a look bit odd. If you do not uncomment the two lines you will get a gray speckled background to the VNC window.
#!/bin/sh # Add the following line to ensure you always have an xterm available. ( while true ; do xterm ; done ) & # 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 &
07. Start the VNC Server
# service vncserver start
08a. Test the VNC Server
Let us assume that mymachine has an IP address of 192.168.0.10. The URL to connect to each of the users will be:
user1 is http://192.168.0.10:5801 user2 is http://192.168.0.10:5802
Connect to http://192.168.0.10:5801. A java applet window will pop-up showing a connection to your machine at port 1. Click the [ok] button. Enter user1's VNC password, and a 1024x768 window should open using the default window manager selected for user1 . The above ports 5801 and 5802 must be open in the firewall {iptables) for the source IP addresses or subnets of a given client.
'''08b. Testing with VNC Client
For user1: vncviewer 192.168.0.10:1 For user2: vncviewer 192.168.0.10:2
To test user1 using vncviewer, vncviewer 192.168.0.10:1. Enter user1's VNC password, and a 1024x768 window should open using user1's default window manager. The vncviewer client will connect to port 590X where X is an offset of 1,2 for user1 and user2 respectively, so these ports must be open in the firewall for the IP addresses or subnets of the clients.
09. Start the VNC Server during boot
# chkconfig vncserver on
10. VNC encrypted through an ssh tunnel
You will be connecting through an ssh tunnel. You will need to be able to ssh to a user on the machine. For this example, the user on the vncserver machine is user1.
10a. Edit /etc/sysconfig/vncservers, and add the option -localhost.
VNCSERVERS="1:user1 2:user2 3:user3"
VNCSERVERARGS[1]="-geometry 1024x768 -localhost"
VNCSERVERARGS[2]="-geometry 1280x1024 -localhost"
VNCSERVERARGS[1]="-geometry 800x600 -localhost"
10b. Restart vncserver
/sbin/service vncserver restart
10c. Go to another machine with vncserver and test the VNC.
a. vncviewer -via user1@192.168.0.10 localhost:1
b. vncviewer -via user2@192.168.0.10 localhost:2
c. vncviewer -via user3@192.168.0.10 localhost:3
By default, many vncviewers will disable compression options for what it thinks is a "local" connection. Make sure to check with the vncviewer man page to enable/force compression. If not, performance may be very poor!
11. Recovery from a logout
If you logout of your desktop manager, it is gone.
- We added a line to xstartup to give us an xterm where we can restart our window manager.
For gnome, enter gnome-session. For kde, enter startkde.
To use different desktop managers instead of the default
If you install VNC on RH Linux / Solaris, the default windowing manager is twm, which isn’t very sexy. Here is how you can switch to something a bit more interesting:
1. vi ./vnc/xstartup in your home directory.
2. Comment out xterm and twn by adding a “#” character at the beginning of the line.
3a. For CDE, add the following line:
/usr/dt/bin/dtwm
3b. For GNOME, add the following lines:
gnome-session& gnome-terminal --geometry 80x24+10+10 --title="My Desktop" &
3c. For KDE, try the following. (Note: I haven’t try this yet. So, let me know if you have comment about this step.)
startkde&
To run vncserver at the resolution you like, try the following on the command-line:
vncserver -geometry 1250x680
The above resolution configuration assumes you have a wide monitor. Please note that vncserver can run at just about any interesting resolution you want, so set it to fit within your local monitor.
For more advanced configuration option, refer
http://wiki.centos.org/HowTos/VNC-Server
http://fedoranews.org/tchung/vnc/01.shtml